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.

MauriceNino
  • 6,214
  • 1
  • 23
  • 60
  • 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). – Rogue Jul 01 '21 at 06:38

2 Answers2

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).

George Karanikas
  • 1,244
  • 1
  • 12
  • 38
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.

M A
  • 71,713
  • 13
  • 134
  • 174
  • 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 Jul 01 '21 at 06:33
  • @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. – M A Jul 01 '21 at 06:43
  • 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. – MauriceNino Jul 01 '21 at 06:44