I read an answer about Maven but I was wondering how I would achieve this task in Gradle - Executing JUnit 4 and JUnit 5 tests in a same build.
Currently my Gradle build only picks up tests with:
import org.junit.jupiter.api.Test;
My problem is that I'm using #RunWith which needs JUnit4 to run but I want to execute it on a JUnit5 Vintage Engine.
How do I make my build such that I can run JUnit4 and JUnit5 together. Thanks.
Update:
Now there is a native Mockito Junit Jupiter for JUnit 5 - https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter
The junit5-migration-gradle project demonstrates how to execute tests based on JUnit 5 using Gradle. In addition, it showcases that existing JUnit 4 based tests can be executed in the same test suite as JUnit Jupiter based tests or any other tests supported on the JUnit Platform.
Basically it boils down to having both engines, Jupiter and Vintage, on the runtime class-path:
dependencies {
testCompile("org.junit.jupiter:junit-jupiter-api:5.2.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.2.0")
}
dependencies {
testCompile("junit:junit:4.12")
testRuntime("org.junit.vintage:junit-vintage-engine:5.2.0")
}
Related
I use Mockito in my Java tests, and have some Scala tests. If I include Scala testCompile dependency then Mockito fail to create a spy when running in IntelliJ, and I get ClassCastException exception.
Can I separate the scala and the java tests, so the java tests have some dependencies and the scala has other dependencies?
If you don't have to run all your tests in the same build, you can use dependency profiles. Lets say scalaTests and javaTests.
And you can group test dependencies like below
dependencies {
....
if (project.hasProperty('scalaTests')) {
//scala test dependencies here
}
else if (project.hasProperty('javaTests'))
//java test dependencies here
}
}
You also have to run only Scala tests when you are using Scala profile(same for java test)
You can run gradle with scalaTests profile like this gradle -PscalaTests .. (same for java case)
For running specific tests
How to run only one test class on gradle
Gradle run only one test suite
For profile details.
https://gist.github.com/szpak/1499336
Maven profiles equivalent of Gradle
I am running Jenkins on Windows 7 as service.
I have approximately 100 selenium test cases in package, but I want to run only 1 test case.
Is it possible to configure Jenkins to run not all, but 1 test?
Depending on how your Jenkins build is configured, somewhere you are specifying the maven goals. These can be configured to specify the test you want to execute, as described here:
mvn -Dtest=TestCircle#mytest test
Note that this require surefire 2.7.3 or later, and Junit 4.X or TestNG:
As of Surefire 2.7.3, you can also run only a subset of the tests in a test class.
NOTE: This feature is supported only for Junit 4.x and TestNG.
For older versions of the Surefire plugin/JUnit, it seems it is only possible to control this on class level, i.e. you cannot specify a specific test in a class:
mvn -Dtest=TestCircle test
Hibernate has its own test infrastructure, that can be used to test Hibernate and its various dialects.
The infrastructure is based on JUnit (the Tests) and Gradle (automation of the test process).
More on it you can find here:
https://github.com/hibernate/hibernate-matrix-testing
https://github.com/hibernate/hibernate-orm/wiki/Hibernate-JUnit-Infastructure
You can start all tests from the test suite using gradle:
gradle hibernate-core:matrix_mysql51
In this case all tests of the hibernate-core module will be started.
There are more than 4000 tests in the module.
I would like to start only some of them.
How do it do it?
Is it possible to use the same testing infrastructure, but start single tests from the testsuite?
gradle hibernate-core:matrix_mysql51 -Dmatrix_mysql51.single=annotations/EntityTest
I have a Java application that uses buildr. My unit test are located in : src/test/java
The buildr doco talks about support for integration tests but where do I put my integration tests? how to I separate them from unit tests?
Each buildr subproject can have either unit tests or integration tests. I use unit tests in each subproject that actually builds an artifact and then a separate subproject just for integration tests.
I ended up defining a subproject for the integration tests. See below:
integration_layout = Layout.new
integration_layout[:source, :test, :java] = _('src/integration/java')
define "integrate", :layout => integration_layout do
test.with TEST_CLASSPATH
test.using :integration
integration.setup { Rake::Task['my_project:jetty_start'].invoke }
integration.teardown { Rake::Task['my_project:jetty_stop'].invoke }
end
I can then run the integration tests with the following command:
buildr integration
I wrote the test case for junit3.
In eclipse test runner there are Junit 3 and Junit4.
If I use junit 4 I can not run each individual testmethod. So I want to use only Junit 3.
I removed the junit4 plugin from eclipse/plugin. Still I am seeing the Junit4 tag in the test runner option.
How can I remove Junit4 from my test runner option?
You can run an individual testmethod with Junit 4. Just right-click on the method in the outline and choose "run with Junit".