2

So we have some tests that only serve a purpose of running them locally. For example, we have a test that uses internal classes to download a file from the cloud.

This test should not be run in our CI, so we put it on @Ignore. There are two downsides with this approach though:

  1. The test is shown as "ignored" in the CI
  2. You have to remove the @Ignore before every run

So I wondered if there is any way to let CI ignore some tests completely, so I can only run them locally?

Just to clarify: This is not about conditionally ignoring tests - it is about hiding tests completely.

1
  • I'd be careful about a catch-all tool like "@Ignore". You're either ignoring a broken test, an improper setup, or a useless test, all of which have bigger issues. As an aside, you could just comment out the @Test annotation if @Ignore was your solution (which is not a real solution here). Commented Jul 1, 2021 at 6:38

2 Answers 2

4

JUnit offers support for @Category (JUnit 4) or @Tag (JUnit 5) allowing you to annotate your individual tests or classes and then selecting the categories you want to run from maven (or you can exclude like in your case by using excludedGroups).

Sign up to request clarification or add additional context in comments.

2 Comments

Can you also select the categories that you want to ignore rather than the ones that you want to run?
Seems like you can by using excludedGroups
1

There are probably many ways to solve that from a technical point of view. For example, if you are using Maven, you could define a custom profile so that when enabled, it excludes these tests.

However, and without having enough context about why this is needed, this seems like a bad thing to do. Ideally you want tests to be runnable in the same way on both the developer machine and the CI. Having tests only run locally is problematic because it lacks all the benefits of the CI.

3 Comments

Thanks! Yes, we are using maven. The problem is that these "tests" aren't really tests, and we only defined them as tests, is so that they can be easily run out of the IDE. So the CI does not have to know about them at all. Do you know any better way to have easily runnable code in your IDE?
@MauriceNino Another way to simple main runnable classes. They won't be run by the maven build. But still: if these "tests" are needed to cover against regressions, they should be part of the CI.
Thank you. No they do not cover any cases. Everything they use is already covered by "real" tests with assertions. These tests exist solely for the purpose of running them locally.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.