Executing testng use cases through code

Source: Internet
Author: User
Tags testng
background

Use TestNG to write the test cases, through the @test to execute the use case, the general local through the IDE to execute the corresponding method, continuous integration, all through Maven to execute or specify Testng.xml execution, but if you want to execute the test case through interface/interface.

Steps

TestNG actually provides two ways to do this through code.

1. Execute by class, show the code:

TestNG TestNG = new TestNG ();
Testng.settestclasses (new class[] {webtestfactory.class});
Testng.run ();

Create a new TestNG object, Settestclass Pass in the class of a use case, then execute the use case run ();

2. Execute via suite, show the code:

Xmlsuite Suite = new Xmlsuite ();
Suite.setname ("Tmpsuite");
XmlTest test = new XmlTest (suite);
Test.setname ("Tmptest");
list<xmlclass> classes = new arraylist<xmlclass> ();
Classes.add (New Xmlclass ("Test.failures.Child"));
Test.setxmlclasses (classes);
        

list<xmlsuite> suites = new arraylist<xmlsuite> ();
Suites.add (suite);
TestNG TNG = new TestNG ();
Tng.setxmlsuites (suites);
Tng.run ();

Notes

If you want to invoke the specified method directly, you need to toss the next

Todo

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.