How to change default test framework in Intellij IDEA? - java

Situation is the following:
I've succesfully created tests in IntellijIDEA with JUnit.
Then when I rightclick on test folder to run tests I accidentally have chosen TestNG instead of JUnit. Now when I try to run tests by right click on tests folder and clicking Run"All tests" it tries to run them in TestNG, but tests are not configured for TestNG that's why I have
Test framework quit unexpectedly, No tests found in the package error
I searched through the internet, but didn't find anything on how to change testing framework by default.
Can anyone help?

Just delete the automatically created TestNG Run/Debug Configuration (Run | Edit Configurations... action) in Run Configurations dialog for the project. Then you will again have the option to choose test framework.
UPD: Since 2017.3 version there is suggest.all.run.configurations.from.context property which you can set (Help | Edit Custom Properties action) to true, then IDE will show you all the configurations that are available for current context.

Related

Does infinitest for IntelliJ IDEA honor the run tests settings in Gradle?

I have a Gradle project that I would like to use infinitest with. However, while all test pass using the Gradle test runner, many fail in infinitest. Is this because infinitest uses the IntelliJ test runner to run the tests?
I expect this is the case since I get similar results when I try to run tests manually using the IntelliJ test runner.
How can I configure infinitest to use Gradle as the test runner?
Infinitest starts a new JVM to run tests, it gets the project classpath from IntelliJ but does not know it is a Gradle project.
I don't know what the Gradle test runner does differently but it would be great if you could open an issue on the Infinitest bug tracker with the steps to reproduce the problem (ideally with a sample project).
In case the issue is with missing JVM options you can set them using the infinitest.args file

IntelliJ IDEA runs full test suite when I try to debug a single unit test

I've inherited a Maven project that includes a large number of unit tests and integration tests. I added a unit test for a change I've made. However, this unit test is failing and so are a number of integration tests (because they rely on a specific environment). I want to debug my unit test (and the method under test), but when I right-click on the test method and choose "debug", IntelliJ IDEA does a "Build" first, and that's the Maven build which tries to execute all tests and integration tests. As a result, the build fails and I can't therefore debug my unit test. How can I get around this?
Intellij has specific configuration for the builds.
The default configuration is the "build" command which will build the project.
You can change this command into a maven command so you will manually skip the tests
to do that click edit configuration and go to the profile configuration you want to change. :
At the very bottom you can see the before launch part :
from there you remove the previous with the ( - ) and you click the ( + ) to add a new one. Scroll down in the list to find the maven goal
once you check it you have to add the manual command there. Note: You dont need to write mvn as its ommited.
An other approach you can follow is to instruct intellij to use maven for all of its actions by delegating everything to maven.
to do that just go to the settings and follow the path :
Build,Execution,Deployment -> Build Tools > Maven > Runner
and check the Delegate IDE build/run actions to Maven.

How to run Maven unit test (testng) on Eclipse?

I have a Maven project and I have included some unit tests. I can run those unit tests from command line using
mvn test -Dtest=AppTest
It will run the unit test (AppTest class) without any problems. But if I tried to run the test on Eclipse as JUnitTest, I got an error saying
"No Tests found with test runner 'JUnit 3'"
I know the test (AppTest) is not a JUnit test but I didn't see "maven" option if I right clicked on the test class.
Do you know how I could run the tests on Eclipse?
If those are testng tests, then you can download the eclipse plugin for TestNG and right click and run them as test class. Testng plugin here
If you want to run the command line way of maven, you would need the maven plugin for eclipse from here
Then you can right click your project and you should see an option of Run As -> Maven Test. You would need to set relevant arguments in the surefire plugin of pom or use run configuration to specify parameters like you did in -Dtest
I would suggest the testng plugin which would be simpler to just select the class and run the class or a single case or a package even.

Excluding JUnit tests in eclipse

Hey
I have a whole bunch of unit tests. I have placed them into suitable test suites. I would like to be able to click on the root directory and go run JUnit tests to execute all the tests. However, if I do this it runs all the tests AND then runs the testsuites. Therefore running all the tests again.
Is there someway to exclude the testsuites in Eclipse?
thanks
When you right click on the project directory and Run As > JUnit test it's basically the relevant run configuration that is being triggered. Therefore go to Run > Run Configurations and on the left panel see exactly what your JUnit configuration is actually doing and configure accordingly.

GWT JUnit test in NetBeans

I have written application in GWT using NetBeans. Now I want to test my application with JUnit. I have never used JUnit before but I have basic concept of how it works. Now the question is how do I setup basic Unit test to test some of my GWT Widgets. I found THIS simple example but don't know how it can be ran in NetBeans.
If you have the test file, right click on it and select "Test file", or press Ctrl+F6.
If you are using a Maven 2 project, you can add the Surefire plugin to run all the test automatically when packaging.

Categories

Resources