22

I have a gradle-based java testing framework.

After updating junit to 5.7.2 this warning started appearing for every test:

Jul 21, 2021 10:23:45 AM org.junit.platform.launcher.core.EngineDiscoveryOrchestrator lambda$logTestDescriptorExclusionReasons$7
INFO: 0 containers and 3 tests were Method or class mismatch

The junit dependencies in use are: junit-jupiter-api, junit-jupiter-engine, junit-jupiter-params.

What may be causing it and what are the potential solutions?

bohdan
  • 425
  • 1
  • 3
  • 8

3 Answers3

29

When you have multiple test methods in 1 class and execute only one of them, that warning appears. if you run all the test methods in that class, it doesn't appear. Judging from the warning message, you have made 4 @Test methods in a class and executed only one of it. The warning message is complaining that 3 other test methods were excluded from execution. If you execute all 4 test methods (Done by running the whole class), that message would disappear. In other words, it is a pointless warning and you can just ignore it.

jeff pentagon
  • 796
  • 3
  • 12
  • 4
    Thank you for the answer! It is quite an annoying experience, writing my first few vanilla project tests and seeing this. The message should be something like "Warning ran 1 out of 4 tests". I don't know what a "Method or class mismatch" is.. – Berik Aug 25 '22 at 10:10
  • 1
    @jeff-pentagon - I'm not sure it's "pointless" but rather confusing. It reads like an error (even though it's marked as "INFO") and might be better rendered like "Test match criteria 'ABC' selects 1 test with 0 containers and 3 tests skipped." I agree that it's of little value when running tests from the IDE where the user presumably understands that the test run is limited. For automation (e.g. script driven testing), it's useful feedback. Even so, I wonder why an INFO message is being written to STDERR... – Stevel Dec 25 '22 at 11:19
10

If your are using Intellij, this might help you.

Preferences > Build, Execution, Deployment > Build Tools > Gradle Set "Build and run using:" and "Run tests using" to "Intellij IDEA"

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
kohei.okamoto
  • 101
  • 1
  • 3
-1

I think the potential solution is adding static import:

import static org.mockito.Mockito.when;

It resolves the problem in my code.

Andronicus
  • 25,419
  • 17
  • 47
  • 88
Ania
  • 1