Java.lang.Exception: No matches found for Intellij IDEA method

I am experiencing the strange behavior of Intellij IDEA 2016.3. Having a class with the foo method and a JUnit test for the method when I get java.lang.Exception: No tests found matching Method foo when starting the test. After executing the mvn test it succeeds, and then runs the unit test immediately after the mvn command is executed, it suddenly starts in green. It seems that IDEA is not compiling automatically. How can i fix this?

PS After updating to version 2016.3, no settings were changed.

+27
source share
11 answers

Well, after the β€œgame” with the launch settings for each unit test, I noticed that in each launch configuration there is a preset of the Build target in the β€œ Before Launch ” option (see Figure below): enter image description here

After changing Build to Build Project tests work fine.

+7
source

Same problem as with Gradle (4.5+) + new Build Cache feature

Sometimes it cannot find new testing methods and throws an exception (as you mentioned in the topic)

Solution: clean .gradle , build and out directories and try again;)

+20
source

If you use a theory testing platform such as Junit's or Robolectric's , be sure to run the class containing the required test, instead the test itself. Since this framework uses testing methods as instance methods instead of static methods, any testing environment looking for a regular public static test will find nothing.

+18
source

Removing the Intellij out directory fixed this problem for me.

+6
source

If you initially ran a test named "foo" and then renamed it "fooBar", you should subsequently run "fooBar" with a new run configuration.

If you use the same initial launch configuration for "foo" to run "fooBar", it is still looking for a test named "foo" that it does not find (thus an exception) because it has been renamed to "fooBar" . The new launch configuration will correctly test the "fooBar" test.

I made this error unknowingly because I renamed the test, but then just pressed the green start button in IntelliJ: for this, the last Run Configuration is executed, which in this scenario has the old name "foo".

+5
source

In addition to the other answers here: an error can also occur if you forget @Test before declaring your testing method. IntelliJ (2018.1) will still show you a green β€œplay button” to run the test, but this public method in your Test-Class will not be a real test.

+4
source

Maybe you are just giving the wrong name for the testing method.

I ran into this problem because I used '-' instead of '_', which intelliJ cannot represent.

+1
source

Make sure you have the right runner mentioned above in your class.

I was getting this strange message when I used the runner CucumberWithSerenity.class . When I changed to SerenityRunner.class , it was fixed.

 @RunWith(SerenityRunner.class) //@RunWith(CucumberWithSerenity.class) public class WordPressAppTest { 

I use the Serenity platform for web automation and use the runner class below

 import net.serenitybdd.cucumber.CucumberWithSerenity; import net.serenitybdd.junit.runners.SerenityRunner; import org.junit.runner.RunWith; 

I feel that IDEA (2017.2.6) may show some error message than this

0
source

Make sure your test is publicly available.

0
source

For those who mix JUnit 4 and JUnit 5 tests (for example, you have JUnit 4 tests, and now you want to add parametric testing with JUnit 5), then this is for you. If you have an import like this:

 import org.junit.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; 

You mixed the import. You can get an exception

java.lang.Exception: no tests were found matching the foo method ...

Update all imports to JUnit 5:

 import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; 

JUnit Vintage exceptions should end.

0
source

This situation may also occur if you do not place the @Test annotation above the test method.

0
source

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


All Articles