【问题标题】:Eclipse plugin junit-tools generated code with @MethodRef, but is undefinedEclipse 插件 junit-tools 使用 @MethodRef 生成代码,但未定义
【发布时间】:2020-01-09 18:37:37
【问题描述】:

我为 Eclipse 安装了 junit-tools 来简化 JUnit 测试的创建。该工具生成的测试类有一个 @MethodRef 注释,但它无法解析,我找不到 jar 文件,甚至找不到要添加的 Maven 依赖项。我也不知道完全限定的包名是什么。问题出在我对生成的文件进行任何修改之前。

关于插件: http://junit-tools.org/index.php 插件名称:org.junit.tools 版本:1.1.0.201811090440 插件 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。

【问题讨论】:

    标签: eclipse junit


    【解决方案1】:

    缺少 Junit-tools jar 文件。 Maven 依赖不起作用。

    <dependency>
        <groupId>net.praqma</groupId>
        <artifactId>junit-tools</artifactId>
        <version>0.1.0</version>
    </dependency>
    

    所以从“http://junit-tools.org/index.php/getting-started”下载依赖的jars文件并将它们放在类路径中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-15
      • 1970-01-01
      • 1970-01-01
      • 2011-06-28
      • 2011-08-06
      • 2011-03-10
      • 2021-01-21
      • 2011-01-28
      相关资源
      最近更新 更多