1 public class Calculator { 2 3 public int add(int a, int b) { 4 return a + b; 5 } 6 7 }
测试代码:
1 public class CalculatorTest extends TestCase { 2 3 Calculator c = new Calculator(); 4 5 public void testAdd() { 6 assertEquals(c.add(3, 4), 7); 7 } 8 9 }
1 [INFO] Scanning for projects... 2 [INFO] 3 [INFO] ------------------------------------------------------------------------ 4 [INFO] Building arazon 1.0-SNAPSHOT 5 [INFO] ------------------------------------------------------------------------ 6 [INFO] 7 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ arazon --- 8 [INFO] Deleting /home/zhw/workplace/maven/arazon/target 9 [INFO] ------------------------------------------------------------------------ 10 [INFO] BUILD SUCCESS 11 [INFO] ------------------------------------------------------------------------ 12 [INFO] Total time: 0.321 s 13 [INFO] Finished at: 2015-03-23T20:25:26+08:00 14 [INFO] Final Memory: 7M/147M 15 [INFO] ------------------------------------------------------------------------
1 ------------------------------------------------------- 2 T E S T S 3 ------------------------------------------------------- 4 Running info.zhw.arazon.CalculatorTest 5 Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.015 sec 6 7 Results : 8 9 Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
最好的教程当然还是官方的文档,简单总结出来的东西难免有所遗漏甚至错误,建议直接看其官方文档,写的也是清晰明了,如果只是想知道怎么用。那个Maven in 5 min已经足够。
原文:http://www.cnblogs.com/sluggard/p/4361365.html