为 Maven fitnesse 插件编写测试
Writing a test for the Maven fitnesse plugin
我刚刚从 uk.co.javahelp.fitnesse 安装了 fitnesse-launcher-maven-plugin,我可以看到它运行良好。
现在我想编写一些测试并在构建过程中查看和执行它们。
我的 pom.xml 文件包含以下插件:
<profiles>
<profile>
<id>wiki</id>
<build>
<plugins>
<plugin>
<groupId>uk.co.javahelp.fitnesse</groupId>
<artifactId>fitnesse-launcher-maven-plugin</artifactId>
<version>1.4.2</version>
<executions>
<execution>
<goals>
<goal>set-up</goal>
<goal>wiki</goal>
<goal>tear-down</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>auto</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>uk.co.javahelp.fitnesse</groupId>
<artifactId>fitnesse-launcher-maven-plugin</artifactId>
<configuration>
<failIfNoTests>false</failIfNoTests>
</configuration>
<executions>
<execution>
<goals>
<goal>set-up</goal>
<goal>run-tests</goal>
<goal>tear-down</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
按照
上的插件网站文档
http://fitnesse-launcher-maven-plugin.googlecode.com
我还创建了以下目录和空文件(暂时):
stephane@stephane-ThinkPad-X301:toolbox> tree src/test/java/fitnesse/
src/test/java/fitnesse/
├── FirstTestSuite
│ ├── content.txt
│ ├── NestedSuite
│ │ ├── AnIndividualTest
│ │ │ ├── content.txt
│ │ │ └── properties.xml
│ │ ├── content.txt
│ │ └── properties.xml
│ ├── properties.xml
│ └── Setup
│ ├── content.txt
│ └── properties.xml
└── plugins.properties
如果运行命令:
mvn verify -P wiki
然后我可以在
看到
http://localhost:9123/
一些不是我的默认 Fitnesse 测试。
另一方面,如果我执行命令:
mvn verify
那么没有要执行的测试:
[INFO] Executed tasks
[INFO]
[INFO] --- fitnesse-launcher-maven-plugin:1.4.2:run-tests (default) @ toolbox ---
[INFO] ------------------------------------------------------------------------
[INFO] Setting FitNesse variable [maven.classpath] to [
!path /home/stephane/dev/java/projects/toolbox/target/test-classes
!path /home/stephane/dev/java/projects/toolbox/target/classes
!path /home/stephane/.m2/repository/org/fitnesse/fitnesse/20140201/fitnesse-20140201.jar
!path /home/stephane/.m2/repository/org/htmlparser/htmlparser/2.1/htmlparser-2.1.jar
!path /home/stephane/.m2/repository/org/htmlparser/htmllexer/2.1/htmllexer-2.1.jar
!path /home/stephane/.m2/repository/org/apache/velocity/velocity/1.7/velocity-1.7.jar
!path /home/stephane/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar
!path /home/stephane/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar
!path /home/stephane/.m2/repository/org/json/json/20090211/json-20090211.jar
!path /home/stephane/.m2/repository/com/googlecode/java-diff-utils/diffutils/1.2.1/diffutils-1.2.1.jar
!path /home/stephane/.m2/repository/org/eclipse/jgit/org.eclipse.jgit/2.3.1.201302201838-r/org.eclipse.jgit-2.3.1.201302201838-r.jar
!path /home/stephane/.m2/repository/com/jcraft/jsch/0.1.46/jsch-0.1.46.jar
]
[INFO] Setting FitNesse variable [org.springframework.version] to [4.2.0.RELEASE]
[INFO] Setting FitNesse variable [java.version] to [1.8.0_60]
[INFO] Setting FitNesse variable [org.springframework.security.version] to [3.2.5.RELEASE]
[INFO] Setting FitNesse variable [project.build.sourceEncoding] to [UTF-8]
[INFO] Setting FitNesse variable [artifact] to [toolbox]
[INFO] Setting FitNesse variable [version] to [0.0.1-SNAPSHOT]
[INFO] Setting FitNesse variable [basedir] to [/home/stephane/dev/java/projects/toolbox]
[INFO] ------------------------------------------------------------------------
[WARNING] No FitNesse Suites or Tests to run! (Set -Dfitnesse.fitnesse.failIfNoTests=false to ignore.)
[INFO] 0 right, 0 wrong, 0 ignored, 0 exceptions
[INFO]
[INFO] --- fitnesse-launcher-maven-plugin:1.4.2:tear-down (default) @ toolbox ---
[INFO]
[INFO] --- fitnesse-launcher-maven-plugin:1.4.2:verify (default) @ toolbox ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.061 s
[INFO] Finished at: 2015-10-26T10:25:17+01:00
[INFO] Final Memory: 19M/205M
[INFO] ------------------------------------------------------------------------
stephane@stephane-ThinkPad-X301:toolbox>
我想用 Slim fixture 写一个非常简单的 Java 测试,比如检查我的业务逻辑 add(2, 2) 方法 returns 4.
我应该在哪个文件中进行 wiki 测试?
我的夹具应该放在哪个文件中?
如何告诉 Fitnesse 执行我的测试?
更新:我的示例夹具是:
public class ExampleFixture {
private String value;
private String result;
public ExampleFixture() {
}
public void execute() {
if (value != null) {
result = Common.trimSpaces(value);
}
}
public void setValue(String value) {
this.value = value;
}
public String getResult() {
return result;
}
}
及其内容:
|Example fixture|
|value|result?|
|some space|somespace|
上一期,关于未找到 result[0] 的问题,是由于我的 getter 读取结果而不是 fixture 内容中的 getResult,现在显示为:
|夹具示例|
|值|得到结果?|
|一些space|一些space|
您已将健身代码放在 src/test/java/fitnesse/
下
默认位置实际上是:src/test/fitnesse/
(去掉java
)
或者,在您的 pom.xml
中配置您要使用的目录:
<testResourceDirectory>src/test/fitnesse</testResourceDirectory>
参见 Plugin Configuration 文档。
更新:
由于 googlecode 已停用,存档站点 returns 某些链接出现 404。有一天我可能会解决这个问题。同时,该项目在 Github 上可用。如果您 运行 maven site
并使用浏览器访问创建的 HTML,文档应该都是完整的。
我刚刚从 uk.co.javahelp.fitnesse 安装了 fitnesse-launcher-maven-plugin,我可以看到它运行良好。
现在我想编写一些测试并在构建过程中查看和执行它们。
我的 pom.xml 文件包含以下插件:
<profiles>
<profile>
<id>wiki</id>
<build>
<plugins>
<plugin>
<groupId>uk.co.javahelp.fitnesse</groupId>
<artifactId>fitnesse-launcher-maven-plugin</artifactId>
<version>1.4.2</version>
<executions>
<execution>
<goals>
<goal>set-up</goal>
<goal>wiki</goal>
<goal>tear-down</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>auto</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>uk.co.javahelp.fitnesse</groupId>
<artifactId>fitnesse-launcher-maven-plugin</artifactId>
<configuration>
<failIfNoTests>false</failIfNoTests>
</configuration>
<executions>
<execution>
<goals>
<goal>set-up</goal>
<goal>run-tests</goal>
<goal>tear-down</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
按照
上的插件网站文档http://fitnesse-launcher-maven-plugin.googlecode.com
我还创建了以下目录和空文件(暂时):
stephane@stephane-ThinkPad-X301:toolbox> tree src/test/java/fitnesse/
src/test/java/fitnesse/
├── FirstTestSuite
│ ├── content.txt
│ ├── NestedSuite
│ │ ├── AnIndividualTest
│ │ │ ├── content.txt
│ │ │ └── properties.xml
│ │ ├── content.txt
│ │ └── properties.xml
│ ├── properties.xml
│ └── Setup
│ ├── content.txt
│ └── properties.xml
└── plugins.properties
如果运行命令:
mvn verify -P wiki
然后我可以在
看到http://localhost:9123/
一些不是我的默认 Fitnesse 测试。
另一方面,如果我执行命令:
mvn verify
那么没有要执行的测试:
[INFO] Executed tasks
[INFO]
[INFO] --- fitnesse-launcher-maven-plugin:1.4.2:run-tests (default) @ toolbox ---
[INFO] ------------------------------------------------------------------------
[INFO] Setting FitNesse variable [maven.classpath] to [
!path /home/stephane/dev/java/projects/toolbox/target/test-classes
!path /home/stephane/dev/java/projects/toolbox/target/classes
!path /home/stephane/.m2/repository/org/fitnesse/fitnesse/20140201/fitnesse-20140201.jar
!path /home/stephane/.m2/repository/org/htmlparser/htmlparser/2.1/htmlparser-2.1.jar
!path /home/stephane/.m2/repository/org/htmlparser/htmllexer/2.1/htmllexer-2.1.jar
!path /home/stephane/.m2/repository/org/apache/velocity/velocity/1.7/velocity-1.7.jar
!path /home/stephane/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar
!path /home/stephane/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar
!path /home/stephane/.m2/repository/org/json/json/20090211/json-20090211.jar
!path /home/stephane/.m2/repository/com/googlecode/java-diff-utils/diffutils/1.2.1/diffutils-1.2.1.jar
!path /home/stephane/.m2/repository/org/eclipse/jgit/org.eclipse.jgit/2.3.1.201302201838-r/org.eclipse.jgit-2.3.1.201302201838-r.jar
!path /home/stephane/.m2/repository/com/jcraft/jsch/0.1.46/jsch-0.1.46.jar
]
[INFO] Setting FitNesse variable [org.springframework.version] to [4.2.0.RELEASE]
[INFO] Setting FitNesse variable [java.version] to [1.8.0_60]
[INFO] Setting FitNesse variable [org.springframework.security.version] to [3.2.5.RELEASE]
[INFO] Setting FitNesse variable [project.build.sourceEncoding] to [UTF-8]
[INFO] Setting FitNesse variable [artifact] to [toolbox]
[INFO] Setting FitNesse variable [version] to [0.0.1-SNAPSHOT]
[INFO] Setting FitNesse variable [basedir] to [/home/stephane/dev/java/projects/toolbox]
[INFO] ------------------------------------------------------------------------
[WARNING] No FitNesse Suites or Tests to run! (Set -Dfitnesse.fitnesse.failIfNoTests=false to ignore.)
[INFO] 0 right, 0 wrong, 0 ignored, 0 exceptions
[INFO]
[INFO] --- fitnesse-launcher-maven-plugin:1.4.2:tear-down (default) @ toolbox ---
[INFO]
[INFO] --- fitnesse-launcher-maven-plugin:1.4.2:verify (default) @ toolbox ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.061 s
[INFO] Finished at: 2015-10-26T10:25:17+01:00
[INFO] Final Memory: 19M/205M
[INFO] ------------------------------------------------------------------------
stephane@stephane-ThinkPad-X301:toolbox>
我想用 Slim fixture 写一个非常简单的 Java 测试,比如检查我的业务逻辑 add(2, 2) 方法 returns 4.
我应该在哪个文件中进行 wiki 测试? 我的夹具应该放在哪个文件中? 如何告诉 Fitnesse 执行我的测试?
更新:我的示例夹具是:
public class ExampleFixture {
private String value;
private String result;
public ExampleFixture() {
}
public void execute() {
if (value != null) {
result = Common.trimSpaces(value);
}
}
public void setValue(String value) {
this.value = value;
}
public String getResult() {
return result;
}
}
及其内容:
|Example fixture|
|value|result?|
|some space|somespace|
上一期,关于未找到 result[0] 的问题,是由于我的 getter 读取结果而不是 fixture 内容中的 getResult,现在显示为: |夹具示例| |值|得到结果?| |一些space|一些space|
您已将健身代码放在 src/test/java/fitnesse/
默认位置实际上是:src/test/fitnesse/
(去掉java
)
或者,在您的 pom.xml
中配置您要使用的目录:
<testResourceDirectory>src/test/fitnesse</testResourceDirectory>
参见 Plugin Configuration 文档。
更新:
由于 googlecode 已停用,存档站点 returns 某些链接出现 404。有一天我可能会解决这个问题。同时,该项目在 Github 上可用。如果您 运行 maven site
并使用浏览器访问创建的 HTML,文档应该都是完整的。