eclipse - Eclipse 插件 junit-tools 使用 @MethodRef 生成代码,但未定义
问题描述
我为 Eclipse 安装了 junit-tools 以简化 JUnit 测试的创建。该工具生成的测试类有一个 @MethodRef 注释,但它无法解析,我找不到 jar 文件,甚至找不到要添加的 Maven 依赖项。我也不知道完全限定的包名是什么。在我对其进行任何修改之前,问题出在生成的文件上。
关于插件: http ://junit-tools.org/index.php 插件名称:org.junit.tools 版本:1.1.0.201811090440 Plugin-Id:org.junit.tools
Eclipse 版本:版本:2018-09 (4.9.0) 内部版本号:20180917-1800
违规代码是 C:\eclipse-workspaces\jdbvc\dbvcs\src\test\java\com\enormacorp\dbvcs\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);
}
}
pom文件:
<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 无法解析为类型
在这个项目的 Eclipse 中的 Java 构建路径中,我只有 JRE 系统库和 maven 依赖项。
我希望这可以解决该工具生成的任何类。我的第一选择是添加一个 Maven 测试范围依赖项。我的第二个选择是将定义 @MethodRef 的任何 jar 显式添加到构建路径中。
如果你读到这里,感谢 Woodsman。
解决方案
推荐阅读
- python-3.x - TensorFlow 2.0:ValueError - 未提供渐变(修改 DDPG Actor 后)
- python - 将生成器对象转换为列表时出现错误“要解压的值太多”
- python - Python IN 运算符有问题
- python - 如何通过在 python 中迭代而不暂停来播放音频?
- python - Python 和模块有不同的路径
- python - 检测大图像中的小图像
- python - python中需要相互获取信息的函数
- django - Django 管理员在末尾显示带有额外“s”的模型名称
- r - 如何在R中的箱线图中添加连接点的线?
- c# - 读取 XML 文件,然后按名称按字母顺序排序