[英]Adding Groovy Tests to Java Maven Project
我一直在Groovy脚本中使用Jsoup来解析html页面。 该脚本通过使用葡萄包含了Jsoup库。
但是,我遇到了一个错误,想修复它。 我能够在Groovy脚本中重复该错误。 我试图通过向项目添加Java测试来复制该错误,但是该测试通过了,因此我无法获得任何有用的信息。
我想通过在Groovy中编写测试来在项目中复制错误。 但是,我不确定为包含和运行Groovy测试需要对pom.xml
进行哪些更改。 任何帮助表示赞赏。
我使用的方法是将GMavenPlus包含到项目中。 第一步涉及对pom.xml
进行必要的更改。 因此,将以下内容添加到<plugins>
部分:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<!-- if including source jars, use the no-fork goals
otherwise both the Groovy sources and Java stub sources will get included in your jar -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<!-- source plugin \> = 2.1 is required to use the no-fork goals -->
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
<goal>test-jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
接下来,将以下内容添加到<dependencies>
部分:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.3</version>
</dependency>
接下来,所有步骤将创建适当的测试目录和测试类:
mkdir src/test/groovy
mkdir -p src/test/groovy/org/jsoup/integration
touch src/test/groovy/org/jsoup/integration/GroovyTest.groovy
然后,我向GroovyTest.groovy
添加了测试,并且能够执行测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.