使用Maven2进行单元测试_我心飞扬_百度空间

使用Maven2进行单元测试_我心飞扬_百度空间

使用Maven2进行单元测试
2008年02月26日 星期二 10:21

Now let's test the application. A few simple test classes can be found in the source code. Unit testing is (or should be!) an important part of any enterprise Java application. Maven completely integrates unit testing into the development lifecycle. To run all your unit tests, you invoke the test lifecycle phase:

现在来测试应用程序,在源代码中可以找到一些简单测试类。单元测试是(或者应该是)任何企业java应用程序的重要组成部分。Maven将单元测试完全集成进了开发生命周期。要运行所有的单元测试,可以调用test生命周期阶段:

mvn test

If you want to run only one test, you can use the test parameter:

如果你只想运行某个单元测试,可以使用test参数指定:

mvn test -Dtest=HotelModelTest

A nice feature of Maven 2 is its use of regular expressions and the test parameter to control the tests you want to run. If you want to run only one test, you just indicate the name of the test class:

Maven 2的一个特性是test参数使用规则表达式来运行测试,如果只想运行某个测试,你只要指出测试类的名称就可以了:

mvn test -Dtest=HotelModelTest

If you want to run only a subset of the unit tests, you can use a standard regular expression. For example, to test all ModelTest classes:

如果你想运行一组单元测试,可以使用标准的规则表达式,比如,为了测试所有的ModelTest类:

mvn test -Dtest=*ModelTest

原文地址:https://www.cnblogs.com/lexus/p/2381300.html