gpt4 book ai didi

java - Eclipse 无法识别测试类

转载 作者:行者123 更新时间:2023-12-02 03:55:21 25 4
gpt4 key购买 nike

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

最佳答案

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

否则你可以通过 Maven 运行它

关于java - Eclipse 无法识别测试类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35524341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com