How to generate JUnit sources using maven-gunit-plugin

1.3k views Asked by At

I have maven configured to run gunit (an ANTLR grammar unit testing tool) through the maven-gunit-plugin. gunit, however, has two different modes. The first mode causes gunit to act as an interpreter, reading through the *.gunit (or *.testsuite) file, interpreting it, and displaying the results. It can be configured as such:

  <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>

The second mode causes gunit to generate source code that can be run by JUnit. How can I instruct the maven-gunit-plugin to generate JUnit sources instead of acting as an interpreter?

A few notes:

  • I can change the test phase to "generate-test-sources" to cause the maven plugin to run at the correct time.
  • I couldn't find any useful documentation on the maven-gunit-plugin
  • I've seen people use exec-maven-plugin to run gunit with a specific command line option, but I'm not looking to do that.

EDIT / RESOLUTION:

After reading the various responses, I downloaded the ANTLR source code, which includes the maven-gunit-plugin. The plugin does not support junit generation. It turns out that the codehaus snapshot of the gunit-maven-plugin and the exec plugin are currently the only options.

2

There are 2 answers

3
Pascal Thivent On BEST ANSWER

I found a discussion through MNG-4039 that is illustrated with a maven-gunit-plugin gunit-maven-plugin sample. I'll let you read the whole article but, according to the author, you should end up with something like this:

<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>

I didn't test this configuration myself and can't thus confirm everything is working out of the box. I don't even know if the plugin has been released in a non SNAPSHOT version. The only thing I can confirm is that it seems indeed very hard to find "real" documentation about the maven-gunit-plugin.

1
sal On

There is sad news here

I found out so far there is no GUnit-functionality (be it JUnit Test-Generation or direct invocation of GUnit) for maven right now. I already mailed with Jim Idle concering the state of GUnit in the
antlr3-maven-plugin and learned that there is a patch to the old version of the maven-plugin waiting in the queue.

I think this workaround that is the only option.