【发布时间】:2011-01-18 13:27:55
【问题描述】:
我正在尝试更新我的 Java 并学习如何使用 Maven 和 JUnit。在 Maven quick start 之后,我在控制台中运行了以下命令:
mvn archetype:generate \
-DgroupId=com.mycompany.app \
-DartifactId=my-app \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DinteractiveMode=false
然后,我在其适当的文件夹中获得了一个简单的 App.java 和一个 AppTest.java。我现在正在查看 AppTest.java 并试图弄清楚如何使用这个 JUnit 东西。问题是我不明白,而且我看起来与我在JUnit Cookbook 中看到的完全不同。比如我从 Maven 得到的版本,包名不同,测试方法没有注解。
这里发生了什么? Maven 使用的不是常规的 JUnit 吗?还是只是在做一些花哨的事情?
更多信息
Apache Maven 3.0.2 (r1056850; 2011-01-09 01:58:10+0100)
Java 版本:1.6.0_23,供应商:Sun Microsystems Inc.
AppTest.java
package com.mycompany.app;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest extends TestCase {
/**
* Create the test case
*
* @param testName
* name of the test case
*/
public AppTest(String testName) {
super(testName);
}
/**
* @return the suite of tests being tested
*/
public static Test suite() {
return new TestSuite(AppTest.class);
}
/**
* Rigorous Test :-)
*/
public void testApp() {
assertTrue(true);
}
}
pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
【问题讨论】: