Excluding JUnit tests in eclipse - java

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.

Related

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 change default test framework in Intellij IDEA?

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.

Android gradle: how to run separately integration and unit tests?

Currently I have standard structure of project:
src
|---androidTest
|-------------------|---java
|----------------------------|---robotium
|----------------------------|---unit
|---main
|---------|---AndroidManifest.xml
|---------|---java
|---------|---res
According to documentation
I've placed unit and integration tests under androidTest folder.
Since instrumentation tests need lot of time, I placed it inside robotium folder(I use Robotium).
Inside unti - jUnit tests respectively.
To run all tests I invoke ./gradlew connectedCheck - it's taking lot of time.
How to to run integration (inside robotium folder) tests and unit tests separately?
I want to run these tests using gradle - it's for CI server.
For example I want to run integration tests every night and unit tests - every hour..
Thanks!
According to the documentation JUnit tests should be places under - src/test/java and then you'll be able to switch between test sources by changing Test Artifact when selecting Build variants as shown:
(source: android.com)

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.

Run all the junit tests that are in a given package in Netbeans?

We have a bunch junit tests in our current project. Essentially we are looking for a way to run all the test in a given package. Currently in Netbeans I see you can run all the tests or a single test, but no way to run a a sub-set of tests.
Is this built into Netbeans? Or is there another way we can do this?
In JUnit this is achieved through TestSuite. You can check for more information here (look at the code, not at the pictures).
At least in the Eclipse IDE there is a functionality that lets you add a new TestSuite, select which tests it is to include and then have the IDE generate it for you.
I haven't seen such thing in Netbeans, but you should check for any additional JUnit plugins.
Just set up junit test groups like documented e.g. on this question and then run the test group via your ant or maven build.

Categories

Resources