2017-07-16 101 views
0

我开始使用java maven项目,我对此很陌生。我使用了Spring注释,当我运行我的测试类时,它给出了以下错误。java中的maven项目中的initializationError(org.junit.runner.manipulation.Filter)

FirstTryTest.testFirst initializationError(org.junit.runner.manipulation.Filter) java.lang.Exception的:未找到匹配的测试 [{ExactMatcher:fDisplayName = testFirst], {ExactMatcher:fDisplayName = testFirst (com.mycompany.test.FirstTryTest)], {LeadingIdentifierMatcher:fClassName = com.mycompany.test.FirstTryTest,fLeadingIdentifier = testFirst]] [email protected] org.junit.internal .requests.FilterRequest.getRunner(FilterRequest.java:40) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.crea teFilteredTest(JUnit4TestLoader.java:77)在 org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68) 在 org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests (JUnit4TestLoader.java:43) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:678) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (RemoteTestRunner.java:192)

我的测试类看起来像这样。

package com.mycompany.test; 

import org.junit.Assert; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.test.context.ContextConfiguration; 
import org.springframework.test.context.TestExecutionListeners; 
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 
import org.springframework.test.context.support.AnnotationConfigContextLoader; 
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; 

import com.mycompany.config.AppConfig; 
import com.mycompany.service.FirstTryService; 

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(classes = { AppConfig.class }, loader = AnnotationConfigContextLoader.class) 
public class FirstTryTest { 

    @Autowired 
    private FirstTryService firstTryService; 

    @Test 
    public void testFirst() { 

     Integer rCal = firstTryService.cal(10, 10); 
     Assert.assertNotNull(rCal); 
     // System.out.println(rCal); 

    } 

    @Test 
    public void testSecond() { 
     System.out.println("hello world"); 
    } 

} 

以下是我的服务和服务impl文件。

package com.mycompany.service; 

import org.springframework.transaction.annotation.Transactional; 

@Transactional 
public interface FirstTryService { 

    Integer cal(Integer x, Integer y); 

} 

package com.mycompany.serviceImpl; 

import org.springframework.stereotype.Service; 

import com.mycompany.service.FirstTryService; 

@Service 
public class FirstTryServiceImpl implements FirstTryService { 

    @Override 
    public Integer cal(Integer x, Integer y) { 
     Integer calPlus = x + y; 

     return calPlus; 
    } 

} 

如何解决此错误?

回答

0

我刚收到与您发布相同的错误。然后我发现这个错误是由测试函数中不必要的输入参数引起的。我不能说你有同样的原因。但是,您可以使用我的步骤来获取错误的细节(看起来这是eclipse的错误,至少它应该增强这个主题)。在运行 - >“运行时选择Junit项目名称时,不要单独选择测试功能来测试,同时在测试选项卡上选择”运行所选项目中的所有测试“选项(调试)配置“。

您可以参考我的回答: JUnit testing got initializationError with java.lang.Exception: No tests found matching