Running TestNG Test in IntelliJ - intellij-idea

After running Rebuild Project successfully in IntelliJ 13.1.3 Ultimate IDE, I opened my Test NG test file.
When right-clicking on the file, I don't see any option to run the test.
How can I run an TestNG test in IntelliJ 13.1.3?
This question is similar, but it's from 2012 with an unaccepted answer.

Yes you can!
Сheck the folder that contains the test classes whether marked as Test Source Root. In another case see whether installed TestNG-J plugin.
Update:

There are 3 possibilities in the new Intellij 2017.2 to run a testNG test.
You can click on the module (project) name >>Run>>All Tests(TNG). Be careful as there are 2 'All Tests' options. The second option is the one you need. It carries a testNG logo. This way you can run all your testNG classes in parallel
The second possibility is to run a single TestNG class. Righ click the class name in the package explorer and choose 'Run Test' If your class is a testNG class, by default, the test will run as a TestNG test.
This option is my favourite as it gives me a lot of control over my tests. Install this 'Create TestNG XML' plugin. Once installed. if you right click on your module name, you will see a new option called 'Create TESTNG XML' and you will be able to directly use that option to run your TestNG tests, giving you a lot of flexibility.

It could be that a plugin that you need is disabled.
Make sure the testNg plugin is enabled.
I noticed this plugin wasn't enabled,
and as soon as I turned it on, everything started working.

Related

IntelliJ Error: Could not find or load main class cucumber.api.cli.Main [duplicate]

I am new to Intellij IDEA. I have a POM based cucumber-selenium project, where I've created cucumber runner classes for each feature file. While working with Eclipse I was able to execute these runner classes by Right click. However in Intellij IDEA (licensed version), even when cucumber-for-java and junit plugins are enabled in Settings window, I dont get Run option.
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class? My main class has code to launch firefox browser and is in different subpackage.
If i mention "cucumber.cli.Main" in Main class, it gives me error - Could not find or load main class cucumber.cli.Main
Please help.
Thanks,
Provided that cucumber support is enabled you should be able to run the test from .feature file's context menu:
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class?
The class is taken from the jar archive attached when enabling Cucumber support in project. By default, the main class name is cucumber.cli.Main:
Do not forget to specify the package where your step definitions are stored in the Glue filed of the Cucumber Run/Debug Configuration.
I changed the Main class in the configuration to io.cucumber.core.cli.Main worked for me.
I was getting the same issue and following the same idea from the #soumya-jain answer's, the package to get Cli class is different if you are using Cucumber version 4.2.6.
This java doc (https://javadoc.io/doc/io.cucumber/cucumber-core/4.2.6/index.html) says the Cli class is located at "cucumber.api.cli.Main".
So, it depends on which Cucumber dependency you are using in your project.
Cheers!

Intellij IDEA Run configurations for Cucumber runner class

I am new to Intellij IDEA. I have a POM based cucumber-selenium project, where I've created cucumber runner classes for each feature file. While working with Eclipse I was able to execute these runner classes by Right click. However in Intellij IDEA (licensed version), even when cucumber-for-java and junit plugins are enabled in Settings window, I dont get Run option.
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class? My main class has code to launch firefox browser and is in different subpackage.
If i mention "cucumber.cli.Main" in Main class, it gives me error - Could not find or load main class cucumber.cli.Main
Please help.
Thanks,
Provided that cucumber support is enabled you should be able to run the test from .feature file's context menu:
Also in Run/Debug configurations window -> Cucumber java -> what should be the main class?
The class is taken from the jar archive attached when enabling Cucumber support in project. By default, the main class name is cucumber.cli.Main:
Do not forget to specify the package where your step definitions are stored in the Glue filed of the Cucumber Run/Debug Configuration.
I changed the Main class in the configuration to io.cucumber.core.cli.Main worked for me.
I was getting the same issue and following the same idea from the #soumya-jain answer's, the package to get Cli class is different if you are using Cucumber version 4.2.6.
This java doc (https://javadoc.io/doc/io.cucumber/cucumber-core/4.2.6/index.html) says the Cli class is located at "cucumber.api.cli.Main".
So, it depends on which Cucumber dependency you are using in your project.
Cheers!

Is it possible to create a list of tests to run in IntelliJ IDEA?

In Visual Studio each test and class with tests has an icon next to it that opens a dropdown to either run the tests, debug the tests or add them to a new test session. IntelliJ IDEA only has the options to run the tests or debug the tests.
Is there any way to create a list of tests from potentially disparate parts of the test suite then run them all in one go?
I'm using Junit 4 and if there's a plugin to do this, that would be satisfactory.
You can right click on a package (and/or a selection of packages) and then choose Run or Debug from the context menu.
Here's a screenshot showing that in action:
The resulting Run Configuration is then available via Run > Edit Configurations where you can edit/add/remove packages/classes from the selected pattern ...
You could also create a JUnit suite or category and let it contain your 'tests of interest' and then run it via IntelliJ's JUnit runner.

IntelliJ,Cucumber, TestNG: Did any one try running a single scenario from the feature file?

I have IntelliJ 2017.1 with TestNG and Cucumber. I can run the test from the testng.xml. However, when I try the same to run from the Cucumber feature file in IntelliJ by right mouse on the scenario and click Run, none of the settings in the testng.xml are honored. There is no way to specify testng.xml for Cucumber in Edit Configurations. Is there a workaround for this? Please help!
To run a scenario
In the Project tool window, right-click the desired feature file, or open it in the editor.
On the context menu of the desired scenario, point to Run, and then choose Run Scenario .

IntelliJ 14 Gradle task in Test Runner

Upgraded to IntelliJ 14.0.1 One of the big new features I was looking for:
"If you run tests via a Gradle task, the IDE offers you the standard Test Runner instead of the console output." (Source: https://www.jetbrains.com/idea/whatsnew/#buildTools)
I right click on the Gradle Task to run our Integration Tests:
However, I see the results of the test still going to console output, not to the Test Runner:
Has anyone been able to get this new feature in IntelliJ IDEA 14 to work?
Thank you in advance,
Philip
Looks like IntelliJ looks for a task named "test" rather than a task of type Test.
https://github.com/JetBrains/intellij-community/blob/master/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/GradleTestsExecutionConsoleManager.java#L191
Rename the test task to unitTest and then create a wrapper that runs both:
// Rename test to unitTest
tasks.test.name = "unitTest"
// Wrap and run both
task test(dependsOn:['unitTest', 'integrationTest'])
If you only want to run integration tests, just overwrite it:
task test(overwrite: true, dependsOn: ['integrationTest'])
This allows me to run the integration tests in the test runner successfully (at least it works in IDEA 15 EAP but it should work in 14 as well I would think).
I still get this in IntelliJ 2017.1, but specifically when running tests in the gradle buildSrc directory. After digging a while, it turns out that the Gradle API doesn’t expose the test tasks in the special buildSrc directory to Intellij, so IntelliJ doesn’t recognize it as a test.
Workaround: Open another IntellIJ project for the buildSrc directory directory instead of trying to run tests cleanly inside the root project.