We are trying to migrate a largish project from maven to gradle.
One hurdle is that the project currently has both JUnit and TestNG tests and that maven supports that very nicely.
I have made some progress teaching gradle to execute both type of tests and create a consolidated report of both, but a final, crucial problem remains:
When the build encounters a test failure it correctly fails … only the first time around.
When I invoke “build” again, the tests are not executed again. (I guess they think they are up-to-date because the first invocation did not fail) and the build “succeeds” even though there is actually still the same test failure.
Example project is at https://github.com/eekboom/gradle-dual-tests
A single gradle test task cannot run both JUnit and TestNG tasks, so here is what I did:
- created a new “testNg” test task
- used “ignoreFailures = true” for both the “test” task (JUnit) and the “testNG” task, so that both tasks are always run even when the first task already encounters a failing tests and so that a consolidated report can be build later on
- a test listener notices if any test fails and sets a flag
- added a new task to build a single test report for both test type results
- added a finalizer task that fails the build if the flag is set