Java lang exception no tests found matching method junit

‘JUnit testing got initializationError with java.lang.Exception: No tests found matching

When running JUnit testing , it gave an initializationError: No tests found matching. Like this:

prodapi-main-junit initializationError(org.junit.runner.manipulation.Filter) java.lang.Exception: No tests found matching [[email protected] at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 

While the testing code is as below:

@RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = ProductApplication.class) @WebAppConfiguration public class HostControllerTest < @Test public void testCreateSite() throws Exception < . >> 

It should be fine to load the class, running well. There’re other modules similar with this one, they’re fine to run.

I have checked the possible causes:

  1. someone said that missing «Test» annotation result in this error. While the code did have the annotation as you can see.
  2. some said the build path should be configured to do the build under the testing source folder, getting the testing class, and export. And that configuration I double-checked worked as well.
  3. maybe testing classes are not generated in the compile time, while I can see those testing classes under the destination folder.

I don’t know whether there’re any other possible things can get Junit testing error like this. Maybe I should check the class loader?

Solution 1: [1]

After googled some answers. I found there’s an issue talked about this case as below: https://github.com/junit-team/junit4/issues/1277 (FilterRequest may hide the real failure cause(exception) of a test) Here’re the steps I tried:
1. don’t select the testing function alone, while select «Run all the tests in the selected project» option on the Test Tab, when select the Junit project name after click on Run->»Run(Debug) Configuration»
2. You can get the details of the error as follows:

initializationError(com.company.product.api.web.rest.HostControllerTest) java.lang.Exception: Method testSetDBConfiguration should have no parameters at org.junit.runners.model.FrameworkMethod.validatePublicVoidNoArg(FrameworkMethod.java:76) at org.junit.runners.ParentRunner.validatePublicVoidNoArgMethods(ParentRunner.java:155) 

3.according to the details given by eclipse above, I removed the argument of that function, the initializedError just disappeared.

Читайте также:  Javascript list css classes

So this issue rises due to the new added testing function has unnecessary input argument. The incorrect code :

@Test public void testSetDBConfiguration(String name) throws Exception  
@Test public void testSetDBConfiguration() throws Exception  

Solution 2: [2]

Had the same issue with PowerMock @RunWith(PowerMockRunner.class) then discovered that my @Test was the wrong implementation. Was using import org.junit.jupiter.api.Test ;

I switched to import org.junit.Test; and that fixed the problem for me.

Solution 3: [3]

I have found the below solution which worked for me.

your Application @SpringBootApplication package name and Test package name should be same .

see if it helps. Happy coding.

Solution 4: [4]

I had the similar problem and later realized that my main spring boot application configuration was not scanning through the packages that had my test classes in

Main class was scanning packages -

Test class was in package - com.mycmp.prj.pkg3

Problem got fixed by fixing our base packages to scan all packages from current project and only scan limited needed packages from dependent libraries

Main java class

@SpringBootApplication(scanBasePackages = ) public class MyApplication extends SpringBootServletInitializer < public static void main(final String[] args) < SpringApplication.run(MyApplication.class, args); >@Override protected SpringApplicationBuilder configure(final SpringApplicationBuilder application) < return application.sources(MyApplication.class); >@Bean public FilterRegistrationBean customFilters() < final FilterRegistrationBeanregistration = new FilterRegistrationBean<>(); final Filter myFilter = new ServicesFilter(); registration.setFilter(myFilter); registration.addUrlPatterns("/myurl1/*", "/myurl2/*"); return registration; > @PostConstruct public void started() < // >> 

My Test Class

**package com.mycmp.prj.pkg3;** import static org.junit.Assert.assertNotNull; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import com.mongodb.MongoClient; @RunWith(SpringRunner.class) @SpringBootTest(classes = MyApplication.class) public class MongoConfigStoreTest < @Test public void testConnection() throws Exception < final MongoClient client = new MongoClient("localhost", 127027); assertNotNull(client); assertNotNull(client.getDatabase("localhost")); >> 

Solution 5: [5]

I had to add the hamcrest-all-1.3.jar into classpath to run unit test.

java.lang.Exception: No tests found matching [[email protected] at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40) 

Solution 6: [6]

Check for below conditions:

  1. Have you used org.junit.jupiter.api.Test; instead of org.junit.Test; for running Junit 4 test cases?
  2. Have you passed an argument to the test method as shown below:

public void test(String arg)

    Re-building a project will also work:

Solution 7: [7]

If it is a maven project run eclipse:eclipse as a Maven build.That resolved my problem.

Solution 8: [8]

First able Make sure that your methods annotated @test as well as the test class are public.

Solution 9: [9]

When you use gradle (and you use codium as IDE) you may need to rebuild it manually, e.g. with ./gradlew build .

Solution 10: [10]

Yup, in VSCode Testing view, I often get the horrible red "InitializationError" for my Java JUnit-based JPA tests and could never figure it out. Based on Mohit Basak comment, I changed

@SpringBootTest(classes = ) public class MyTest
@SpringBootTest(classes = ) public class MyTest

and so far I think it's working better now. The tests always ran green/complete and even runs fine from command line with gradle build

Solution 11: [11]

I had a similar error when my test method was private. It needs to be public.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run a single test method from idea: java.lang.Exception: No tests found matching Method . from org.junit.vintage.engine.descriptor.RunnerRequest #789

Unable to run a single test method from idea: java.lang.Exception: No tests found matching Method . from org.junit.vintage.engine.descriptor.RunnerRequest #789

Comments

Using IDEA version that provides support for junit 5 M3

IntelliJ IDEA 2017.1
Build #IC-171.3780.107, built on March 22, 2017
JRE: 1.8.0_112-release-736-b13 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 7 6.1

When attempting to run a single java test method (right click on method name and select run) I get the exception below. If I run the entire test class everything passes successfully. Attaching the full console output (full.txt)

 WARNING: Method 'public void com.pcbsys.nirvana.client.nChannelToChannelJoinTests.subscribeAndPublishTest() throws java.lang.Exception' could not be resolved java.lang.Exception: No tests found matching Method subscribeAndPublishTest(com.pcbsys.nirvana.client.nChannelToChannelJoinTests) from org.junit.vintage.engine.descriptor.RunnerRequest@3911c2a7 at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40) at org.junit.vintage.engine.discovery.TestClassRequestResolver.determineRunnerTestDescriptor(TestClassRequestResolver.java:74) at org.junit.vintage.engine.discovery.TestClassRequestResolver.addRunnerTestDescriptor(TestClassRequestResolver.java:63) at org.junit.vintage.engine.discovery.TestClassRequestResolver.populateEngineDescriptorFrom(TestClassRequestResolver.java:57) at org.junit.vintage.engine.discovery.JUnit4DiscoveryRequestResolver.populateEngineDescriptor(JUnit4DiscoveryRequestResolver.java:88) at org.junit.vintage.engine.discovery.JUnit4DiscoveryRequestResolver.resolve(JUnit4DiscoveryRequestResolver.java:49) at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:47) at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:109) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:85) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:61) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 

Original issue logged under IDEA project but looks like it belongs to JUNIT: https://youtrack.jetbrains.com/issue/IDEA-170573

The text was updated successfully, but these errors were encountered:

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem executing remote Spock test due to java.lang.Exception failure #1587

Problem executing remote Spock test due to java.lang.Exception failure #1587

Comments

Trying to execute remote tests using JUnit 4.12 with Groovy&co steroids from IDEA:

image

java.lang.Exception: No tests found matching method name filter from org.junit.runner.Request$1@3af039ed at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at org.junit.runner.JUnitCore$run$0.call(Unknown Source) at com.onresolve.scriptrunner.canned.common.admin.RunUnitTests.doScript(RunUnitTests.groovy:320)

Issue can be reproduces also by another JUnit users on this repo

The text was updated successfully, but these errors were encountered:

Источник

Оцените статью