0

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

1 回答 1

2

检查您是否安装了 TestNG 插件。 http://singinginthesunlight.blogspot.in/2016/02/testng-for-dummies.html

否则你可以通过 Maven 运行它

于 2016-02-20T14:13:34.400 回答