我有这个类,但是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>