我在eclipse中设置了一个“Maven Project”(简单项目)并为它添加了一个类和单元测试。测试运行良好。但是,只要我将“module-info.java”添加到“src/main/java”,单元测试就无法启动:错误:无法找到或加载主类workspace2.unittest.target.test-classes引起:java.lang.ClassNotFoundException:workspace2.unittest.target.test-classes信息:“workspace2”是我的工作空间的名称,“unittest”是项目名称。如果我通过控制台运行 maven(相同的 maven 和 java 版本),它运行良好。设置:-eclipse:2018-12 (4.10.0)-maven:3.6.0(在 eclipse 中配置)-java:oracle-jdk-9.0.4 / openjdk-11.0.2_linux-x64其他人有过这种问题吗?我用 JUnit4(4.12 和 4.13-beta-1)和 JUnit5(5.3.2)进行了尝试。更新 这里是一个压缩示例项目的链接:https ://www.file-upload.net/download-13475608/unittest.zip.html起居室:<modelVersion>4.0.0</modelVersion><groupId>de.test</groupId><artifactId>unittest</artifactId><version>0.0.1-SNAPSHOT</version><properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target></properties><dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency></dependencies>模块信息.java:module de.unittest {}班级:package unittest;public class Demo { public int calculate(int a, int b) { return a + b; }}测试:package unittest;import static org.junit.Assert.assertEquals;import org.junit.Before;import org.junit.Test;public class DemoTest { private Demo demo; @Before public void setUp() throws Exception { demo = new Demo(); } @Test public void testCalculate() throws Exception { int calculated = demo.calculate(1, 2); assertEquals(3, calculated); }}
添加回答
举报
0/150
提交
取消
