How to ignore a test in the JUnit test method itself

We have a number of integration tests that fail when our staging server goes into weekly maintenance. When the staging server is down, we send a specific response that I might find in my integration tests. When I get this answer instead of rejecting the tests, I wonder if it is possible to skip / ignore this test, even if it started working. This will simplify our test reports.

Does anyone have any suggestions?

+4
source share
3 answers

It has been a while since I used JUnit, but there is no way to Assume condition is true? I think this has a different meaning than skipping / failing a test. Your report should indicate that the test has not been run.

Edited to add: Assume a class

+11
source

In your test, you can verify this condition before executing Assert.whatever. If the test doesn’t allow you to simply return from the method without running the rest of the code / approves.

0
source

The simplest solution would be to break the tests into two sets: integration tests and pure unit tests. Then create a script or some other automated tool to determine if the server is running, and just skip the integration testing package if the server is down. But if grouping the tests into similar suites is impractical for some reason, here is an alternative:

You can create a custom Runner that skips tests if the server is unavailable. You can either program the runner to determine server availability yourself, or define it through some external process, such as a script that runs before the testing phase and sets the JVM system property that the runner can check (for example, pass -Dcom.company.testrun.integration=false as a command line argument).

You can enable your own runner using the @RunWith annotation on your integration test classes, and use the built-in runner for all other tests so that they are not affected. Alternatively, you can use your runner for all tests and come up with a new annotation (like @IntegrationTest ) that you use to decorate your integration testing methods. Using the latter approach, the runner will apply his skip logic only if the server is unavailable and the test method has a special annotation.

0
source

Source: https://habr.com/ru/post/1308918/


All Articles