When writing code that interacts with external resources (such as using a web service or other network operation), I often structure the classes so that it can also be \"stu
You can use @Ignore
annotation to prevent them from running automatically during test. If required, you may trigger such Ignored tests manually.
@Test
public void wantedTest() {
return checkMyFunction(10);
}
@Ignore
@Test
public void unwantedTest() {
return checkMyFunction(11);
}
In the above example, unwantedTest
will be excluded.
As far as I can see you use gradle and API for JUnit says that annotation @Ignore
disables test. I will add gradle task which will add @Ignore
for those tests.
I recommend using junit categories. See this blog for details : https://community.oracle.com/blogs/johnsmart/2010/04/25/grouping-tests-using-junit-categories-0.
Basically, you can annotate some tests as being in a special category and then you can set up a two test suites : one that runs the tests of that category and one that ignores tests in that category (but runs everything else)
@Category(IntegrationTests.class)
public class AccountIntegrationTest {
@Test
public void thisTestWillTakeSomeTime() {
...
}
@Test
public void thisTestWillTakeEvenLonger() {
....
}
}
you can even annotate individual tests"
public class AccountTest {
@Test
@Category(IntegrationTests.class)
public void thisTestWillTakeSomeTime() {
...
}
Anytime I see something manually getting turned on or off I cringe.
If you're just wanting to disable tests for functionality that hasn't been written yet or otherwise manually disable some tests temporarily, you can use @Ignore; the tests will be skipped but still noted in the report.
If you are wanting something like Spring Profiles, where you can define rulesets for which tests get run when, you should either split up your tests into separate test cases or use a Filter.