代码之家  ›  专栏  ›  技术社区  ›  Kaleb Pederson

如何使用maven gunit插件生成JUnit源代码

  •  3
  • Kaleb Pederson  · 技术社区  · 16 年前

    我已将maven配置为运行 gunit (ANTLR语法单元测试工具)通过 maven-gunit-plugin . 然而,gunit有两种不同的模式。第一种模式使gunit充当解释器,读取*.gunit(或*.testsuite)文件,对其进行解释,并显示结果。可以将其配置为:

      <plugin>
        <groupId>org.antlr</groupId>
        <artifactId>maven-gunit-plugin</artifactId>
        <version>3.1.3</version>
        <executions>
            <execution>
                <id>maven-gunit-plugin</id>
                <phase>test</phase>
                <goals>
                    <goal>gunit</goal>
                </goals>
            </execution>
        </executions>
      </plugin>
    

    几点注意事项

    • 我找不到任何关于maven gunit插件的有用文档
    • 我见过有人用 exec-maven-plugin 使用特定的命令行选项运行gunit,但我不打算这样做。

    编辑/解析:

    在阅读了各种回复之后,我下载了ANTLR源代码,其中包括maven gunit插件。这个插件可以 支持junit生成。事实证明,gunit maven插件的codehaus快照和exec插件是目前唯一的选项。

    2 回复  |  直到 16 年前
        1
  •  3
  •   Pascal Thivent    16 年前

    我找到了一个 discussion MNG-4039 这用一个例子来说明 maven-gunit-plugin gunit-maven-plugin 样品我会让你读整篇文章,但根据作者的说法,你应该以这样的方式结束:

    <dependencies>
      <dependency>
        <groupId>org.antlr</groupId>
        <artifactId>antlr-runtime</artifactId>
        <version>3.1.1</version>
      </dependency>
      <!-- Here is the 'extra' dep -->
      <dependency>
        <groupId>org.antlr</groupId>
        <artifactId>antlr</artifactId>
        <version>3.1.1</version>
        <!-- we try to use scope to hide it from transitivity -->
        <scope>test</scope> <!-- or perhaps 'provided' (see later discussion) or 'import' (maven >= 2.0.9) -->
      </dependency>
    </dependencies>
    <build>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>gunit-maven-plugin</artifactId>
          <version>1.0.0-SNAPSHOT</version>
          <executions>
            <execution>
              <goals>
                <goal>generate</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
    

    我没有亲自测试这个配置,因此无法确认一切正常。我甚至不知道插件是否以非快照版本发布。我唯一能确认的是,似乎确实很难找到有关该项目的“真实”文档 .

        2
  •  1
  •   sal    16 年前

    有个坏消息 here

    GUnit功能(无论是JUnit 测试生成或直接调用 现在就给maven。我 已经和吉姆·康辛一起寄了 美国的冈尼特状态
    antlr3 maven插件,并了解到 旧版本的有一个补丁

    我想 this 这是唯一的选择。

    推荐文章