0
votes

I have a project, with tests implemented by junit 4 and 5. Some of the tests require a database to be present, is there any way I can mark these specific tests (is TestSuite the answer?), so gradle continue the build even if those tests fail?

I don't want to skip other tests, but just these specific tests.

And I am using junit 5 vintage, so my test task runs both junit 4 and junit 5 tests together.

1

1 Answers

1
votes

Honestly, I wouldn't do this. What is the point of a test if you ignore it when it fails? You might as well delete the test right away. Can't you delay test execution if setup is slow?

That said...

gradle --continue will continue execution when a task fails, collecting all the errors. You may still need to ignore Gradle's exit code (e.g., in a build pipeline).

You can also use the ignoreFailures test property to always ignore failing tests.

Both may be a bit too broad. Depending on your build script, you could add have a separate test target for database tests and add ignoreFailures only to that.

If you want to handle this in JUnit, you could look into the Assume class which lets you skip a test if a certain condition is (or is not) given:

import static org.junit.Assume.*;

public class SomeDatabaseTest {
    @Test
    public void someThing() {
        assumeTrue(Database.isAvailable());
        // actual test goes here
    }
}