2017-03-02 66 views
1

我有以下的測試代碼:的IntelliJ的JUnit @RunWith沒有解決

package soundSystem; 

import static 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.junit4.SpringJUnit4ClassRunner; 


@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(classes = CDPlayerConfig.class) 

public class SonyCDPlayerTest { 

@Autowired 
private ICompactDisk cd; 

@Test 
public void cdShouldNotBeNull() { 
    assertNotNull(cd); 
} 

} 

這是一個Maven項目,問題是完全相同的代碼將在Eclipse中運行,而不是在的IntelliJ。

我無法找到一個方法來解決@RunWith

screen shot from intellij

回答

1

簡單:你的IDE是配置進行單元測試。

換句話說:你錯過了全部 JUnit相關的類。你可以看到所有的這些JUnit進口都有下劃線;因爲IntelliJ根本不知道包含相應類的JAR。

有關如何解決該問題,請參見here

+0

真的真的ty,我一直在整個下午都在打架,之前我不知道應該在項目結構中添加jar,但是我仍然不明白爲什麼我必須手動添加它我的maven pom有junit和項目結構有maven:junit –

+0

那部分我不能告訴你;-( – GhostCat

+0

ty都是一樣的,:-) –

相關問題