我为Eclipse安装了junit工具,以简化junit测试的创建。该工具生成的测试类有一个@MethodRef注释,但它无法解析,我找不到jar文件,甚至找不到要添加的Maven依赖项。我也不知道完全限定的程序包名称是什么。问题出在我对生成的文件进行任何修改之前。
关于插件:< br > http://junit-tools.org/index.php
插件名称:org.junit.tools
版本:1.1.0.201811090440
插件Id: org.junit.tools
Eclipse 版本:
版本: 2018-09 (4.9.0)
内部版本 ID: 20180917-1800
有问题的代码是C:\eclipse workspaces\jdbvc\dbvcs\src\test\java\com\enormacorp\dbvces\model\ConnectionInformationTest.java
package com.enormacorp.dbvcs.model;
import javax.annotation.Generated;
import org.junit.Test;
@Generated(value = "org.junit-tools-1.1.0")
public class ConnectionInformationTest {
private ConnectionInformation createTestSubject() {
return new ConnectionInformation();
}
@MethodRef(name = "getJdbcDriverClassName", signature = "()QString;")
@Test
public void testGetJdbcDriverClassName() throws Exception {
ConnectionInformation testSubject;
String result;
// default test
testSubject = createTestSubject();
result = testSubject.getJdbcDriverClassName();
}
@MethodRef(name = "setJdbcDriverClassName", signature = "(QString;)V")
@Test
public void testSetJdbcDriverClassName() throws Exception {
ConnectionInformation testSubject;
String jdbcDriverClassName = "";
// default test
testSubject = createTestSubject();
testSubject.setJdbcDriverClassName(jdbcDriverClassName);
}
}
聚甲醛文件:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.enormacorp.dbvcs</groupId>
<artifactId>main</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>com.enormacorp.dbvcs.main</name>
<packaging>pom</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Eclipse错误:MethodRef无法解析为类型
在这个项目的EclipseJavaBuild Path中,我只有JRE系统库和maven依赖项。
我希望这能解决该工具生成的任何类。我的第一个选择是添加一个Maven测试范围依赖项。我的第二个选择是显式地将jar定义的@MethodRef添加到构建路径中。
它缺少Junit工具jar文件。Maven依赖性不起作用。
<dependency>
<groupId>net.praqma</groupId>
<artifactId>junit-tools</artifactId>
<version>0.1.0</version>
</dependency>