我有以下测试代码:
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 的方法
最佳答案
@RunWith
注解在 JUnit 5.0 及更高版本中被替换为 @ExtendWith
(最新的 spring 版本正在使用)。
例子:
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = { SpringTestConfiguration.class })
public class GreetingsSpringTest {
// ...
}
引自 Baeldung:
Note that SpringExtension.class is provided by Spring 5 and integrates the Spring TestContext Framework into JUnit 5.
关于java - intellij junit @RunWith 未解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42550874/