TestNG Official Document Chinese version (9)-Repeat failure test, junit test, jdk1.4 support

Source: Internet
Author: User
Tags command line testng

5.10-rerunning failed Tests

When a test in a suite fails, each testng creates a file named Testng-failed.xml in the output directory. This XML file contains the necessary information to rerun only these failed test methods, allowing only those failed tests to run without having to run all the tests. Thus, a typical scenario would be this:

java -classpath testng.jar;%CLASSPATH% org.testng.TestNG -d  test-outputs testng.xml
java -classpath testng.jar;%CLASSPATH% org.testng.TestNG -d test- outputs test-outputs\testng-failed.xml

Note that Testng-failed.xml will contain all the necessary dependency methods, so you can guarantee that the failed method is run without running any skipped (failed) methods.

5.11-junit Tests

TestNG can run JUnit tests. All that is required is to specify the JUnit test class in the Testng.classnames property and set the Testng.junit property to True.

<test name="Test1" junit="true">
   <classes>
     <!--  -->

In this case testng behaves like Jnit:

* All methods beginning with test* in the class will be run.

* If there is a method setup () in the test class, it will be executed before each test method call.

* If there is a method teardown () in the test class, it will be executed after each test method call.

5.12-JDK 1.4

TestNG can also work under the JDK1.4. In this case, you need to use the published jdk1.4 jar file (named TestNG-...-Jdk14.jar). The only difference is that the annotations, jdk1.4, use the popular xdoclet Javadoc annotation syntax:

public class SimpleTest {
  /**
   * @testng.before-class = "true"
   */
   public void setUp() {
     // code that will be invoked when this test is  instantiated
  }
  /**
   * @testng.test groups = "functest" dependsOnGroups =  "group1,group2"
   */
   public void testItWorks() {
     // your test code
  }
}

The rules for Javadoc syntax are very concise, and the only difference between jdk1.5 annotations is that arrays of array strings need to be specially written as separate, comma-or space-delimited strings. Although double quotes around values are optional, it is recommended that you use double quotes in all cases to make it easier to migrate to jdk1.5 in the future.

It is also necessary to indicate the SourceDir attribute in the <testng> ant task (or use-sourcedir on the command line) so testng can find the source code for your test file to parse the Javadoc annotation.

Here are the syntax tables for the notes of jdk1.4 and Jdk5:

(table in the blog is not good typesetting, not here, please refer to the Official document details of the original: Http://testng.org/doc/documentation-main.html#jdk-14.) )

For more jdk1.4 support examples, refer to the Test-14 folder in the distribution package, which contains all JDK 1.5 test-related content that uses Javadoc annotations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.