我有这个类,但是eclipse并不认为它是一个测试类,所以我不能将它作为Junit测试运行,我使用TestNG是一个受JUnit和NUnit启发的测试框架,但引入了一些新功能它更强大,更易于使用,
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class ApplicationServiceImplTest {
@Mock
ApplicationDao dao;
@InjectMocks
ApplicationMutatorServiceImpl applicationMutatorServiceImpl;
@BeforeClass
public void setUp(){
MockitoAnnotations.initMocks(this);
}
@Test
public void testSave() throws Exception {
Application application = new Application();
applicationMutatorServiceImpl.save(application);
System.out.println (application);
}
}
在我的pom.xml中
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
答案 0 :(得分:2)
检查您是否安装了TestNG插件。 http://singinginthesunlight.blogspot.in/2016/02/testng-for-dummies.html
否则你可以通过Maven
运行它答案 1 :(得分:0)
清洁并构建您的工作区