2017-07-16 99 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