2016-01-22 130 views
6

我想弄清楚爲什麼我得到錯誤的原因,當我試圖運行一些測試創建並運行了一段時間。這是測試類:Junit測試與@RunWith(PowerMockRunner.class)失敗 - 「沒有測試發現匹配..」

package com.chw.pxi.impl.oneway.formatter; 

import org.junit.Before; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.powermock.modules.junit4.PowerMockRunner; 

@RunWith(PowerMockRunner.class) 
public class OnewayOldFormatterTestsWhy 
{ 
    @Before 
    public void setUp() 
    { 
    } 

    @Test 
    public void 
    test_nothing() 
    { 
     System.out.println("Yep"); 
    } 

} 

以下是錯誤當我嘗試運行由「test_nothing」方法上單擊右鍵,選擇「運行方式/ JUnit測試」。

java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test_nothing], {ExactMatcher:fDisplayName=test_nothing(com.chw.pxi.impl.oneway.formatter.OnewayOldFormatterTestsWhy)], {LeadingIdentifierMatcher:fClassName=com.chw.pxi.impl.oneway.formatter.OnewayOldFormatterTestsWhy,fLeadingIdentifier=test_nothing]] from [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) 

該項目的構建路徑中有很多jar文件。我想我應該嘗試創建一個新項目並查看問題是否存在。旁註 - 當我運行在具有此另一個測試方法的測試 - 它在運行時上述錯誤罰款:

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations={"dao-tests-context.xml"}) 
@TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true) 
//Note: This is a live database test but transactions will be rolled back 
//except those that invoke methods that require new transactions 
public class AgencyDaoTests 

如果需要更多的信息,請讓我知道什麼,我怎麼能去爲你獲取這些信息。

謝謝,邁克爾

+0

你是否嘗試使用另一個類名?例如:OnewayOldFormatterTest –

+0

上面的方法是一個大的Junit測試,之前工作過,我創建了它。起初,我對你的建議不太清楚,但將課程改名爲另一個名稱。同樣的結果。我甚至用相同的結果嘗試過其他測試類。我已經爲這個問題做了大量的搜索,並且完成了所有的建議但沒有結果。它必須是我的電腦,因爲同事可以在沒有問題的情況下運行。 – schu777

+0

我想說'PowerMockRunner'試圖找到所有的PowerMock值來替換它們自己的實現。它似乎沒有設置任何。嘗試添加一個'@ PrepareForTest'註釋,並至少有一個類,以便它可以被選擇... – SKBo

回答

6

至於'org.powermock:powermock-api-mockito2:1.6.5'版本Powermock我管理這個從方法層面移動@PrepareForTest批註一流水平的工作。

+0

偉大的,拯救我的一天!謝謝! – Brain

+0

謝謝..救了我的一天 – Asthme