Gradle 4.6 added support for JUnit5.
This works for me as long as I don't have another sourceset for e.g. integration tests: I do not know how to enable useJUnitPlatform() in my integration tests.
What I was able to do is to have test task working with new JUnit5 support, but my testInt task was using JUnit5 console and running tests as it would run from command line. At the end I ditch JUnit5 support in gradle and rollback to using JUnit5 console for both tests.
How to enable Gradle 4.6 JUnit5 support on other tasks then test?
If your integration test task is also a Test task, you may configure all test tasks via:
tasks.withType(Test) {
useJUnitPlatform()
}
Or configure it explicitly:
task testInt(type: Test) {
useJUnitPlatform()
...
}
Related
We have a Azure Pipeline with Gradle Task which runs almost 1700 unit tests. There are some flaky tests (2-3)which is causing the build to fail or partially succeed. Is there a way that I can bypass these flaky tests and have the build run successfully? Thanks in Advance.
In build.gradle, add this:
test {
ignoreFailures = true
}
You can find the documentation here.
Better still, if you know exactly what are the flaky tests, you can exclude them as follows:
test {
// explicitly exclude tests
exclude 'org/boo/**'
}
And if there is no choice, or you are in a rush, you can skip all the tests:
gradlew build -x test
I have jacoco set up for my project.
I can do:
gradle cleanTest test
followed by
gradle jacocoTestReport
and get code coverage
This means two steps. Is there any way, I can just pass a switch to gradle test and get it
https://docs.gradle.org/current/userguide/jacoco_plugin.html
If the Java plugin is also applied to your project, a new task named
jacocoTestReport is created that depends on the test task.
So just call gradle jacocoTestReport, the test will also be invoked first.
edit : if you really want to call the test task, just add this in your build.gradle :
test.finalizedBy jacocoTestReport
Is it possible to run a TestNG test suite that is embedded in a JAR file via a Gradle test task?
My project includes JARed bundles of TestNG tests that have an embedded testng.xml file defining which tests should be run in the JAR. Is it possible for Gradle to refer to this embedded XML when running the TestNG tests?
From the command line I use the xmlpathinjar option.
I dont think it can be done using the Gradle TestNG task. I couldn't find any such support in the TestNGOptions
Instead of using
test{
useTestNG()
}
you could try going through this post on SO How can I tell Gradle to use my testng.xml file for Test Classes and Ordering? and maybe employ the approach detailed here https://stackoverflow.com/a/28868416
But when you are using a custom Gradle task to run your TestNG tests, please make sure that you add a reference to the ExitCodeListener
Here's a sample
task ('myTask', type: JavaExec) {
main = 'org.testng.TestNG'
classpath = sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath
args = ["-xmlpathinjar", "suites/mysuite.xml", "-listener", "org.testng.TestNG\$ExitCodeListener"]
}
More details on why the ExitCodeListener needs to be referred, can be found here
Using the latest version of gradle (2.10) with the Scala Plugin enabled, I'm trying to execute the tests located at src/test/scala.
But there seems to be no tasks to run these:
$ ./gradlew tasks
....
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
None of these 2 tasks will execute my Scala tests. The only tests that get executed are those in src/test/java. My Scala tests tests are using Specs2 using the following dependencies for test (build.gradle):
apply plugin: 'scala'
dependencies {
testCompile(
'org.specs2:specs2-core_2.12.0-M3:3.6.6-scalaz-7.2.0'
)
}
I checked: the tests are getting compiled when using ./gradlew compileTestScala.
What needs to be done to execute these tests?
Ok, it was easy:
import org.specs2.runner.JUnitRunner
#RunWith(classOf[JUnitRunner])
class FooSpec extends Specification {
// test code
...
}
Another solution: using gradle plugin com.github.maiflai.scalatest
For such solution, Scala tests will be ran using org.scalatest.tools.Runner.
dependencies {
implementation 'org.scala-lang:scala-library:2.13.3'
testImplementation 'org.scalatest:scalatest_2.13:3.2.0'
testImplementation 'junit:junit:4.13'
testImplementation 'com.vladsch.flexmark:flexmark-all:0.35.10'
}
version of flexmark is important because of scalatest framework hard coded such version in their code
I am trying to set-up code coverage for my project. I am using Wildfly 8.2 server, gradle as a build tool, and JUnit and Arquillian for testing. In gradle I have configured jacoco plugin to generate code coverage. I have a task called jacocoTestReport which allows me to generate an html report.
Something about running the tests:
I am working on a multi module project, each sub-project has a Deployments class in which we have two methods - one for creating a shrinkwrap archive of REST classes and other for non-REST classes. In arqullian.xml we are configuring this as REST_CONTAINER and NON_REST_CONTAINER and giving path to WildFly installation directory. When we run gradle build test , It will run the whole tests by deploying the REST.ear and non-REST.ear and generate the coverage reports.
The issue is code coverage for EJB's and other server managed classes are showing 0% (From primary ananlysis of coverage report). Also I analysed the jacoco.exec, there I found the classes which are showing 0% coverage are not listed in the file (Mostly bean classes).
Can someone provide me the correct configuration which works for the combination: Wildfly-Arquillian-Gradle-Jacoco
Note: I am ok to use tools other than jacoco, tried cobertura but same result.
This worked for me (but I used jboss7 should not be a problem) source:https://developer.jboss.org/thread/241883
apply plugin: 'jacoco'
jacoco {
toolVersion = '0.7.4.201502262128'
reportsDir = file("$buildDir/jacoco")
}
dependencies {
testCompile 'YOUR_ARQUILLIAN_ADAPTER'
testCompile 'org.jboss.arquillian.junit:arquillian-junit-container:1.1.5.Final'
testCompile 'org.jboss.arquillian.extension:arquillian-jacoco:1.0.0.Alpha7'
}
// Important: add the Jacoco libs on the test classpath (required for the Jacoco Arquillian extension to work).
sourceSets {
test.runtimeClasspath += configurations.jacocoAnt
}