TestNG relies on simple method dependencies for testing, configuring dependent methods through the Dependsonmethods property
Original articles, all rights reserved, permitted reprint, Mark Source: Http://blog.csdn.net/wanghantong
Java Code:
[Java]View PlainCopy
- /**
- *
- * <p>
- * Title:testngdependencies
- * </p>
- *
- * <p>
- * Description:testng provides two kinds of dependency implementations
- *
- * 1. Forced dependency: If there is a failure in a dependency chain that needs to be executed before a test case, then all of the tests will not be executed
- * 2. Sequential dependencies (soft dependencies): The usefulness of sequential dependencies is more used to detect whether a test chain executes in the correct order, even if one of the use cases fails, but does not affect the execution of the entire test chain
- * Dependsonmethods
- * (If the dependent method has multiple overloaded methods, all overloaded methods will be executed, and if you want to execute only one method, use dependsongroups)
- * </p>
- *
- * <p>
- * Company:
- * </p>
- *
- * @author: Dragon
- *
- * @date: October 13, 2014
- */
- Public class Testngdependencies {
- @Test
- public void Serverstartedok () {
- System.err.println ("method1 runs after me ...");
- }
- @Test (dependsonmethods = { "Serverstartedok"})
- public void Method1 () {
- System.err.println ("I am depended on serverstartedok ...");
- }
- }
Configuration file:
[HTML]View PlainCopy
- <? XML version= "1.0" encoding="UTF-8"?>
- <! DOCTYPE Suite SYSTEM "Http://testng.org/testng-1.0.dtd">
- <suite name="framework_testng" allow-return-values="true">
- <test verbose="2" name= "testngdependencies">
- <classes>
- <class name="com.dragon.testng.annotation.TestngDependencies">
- </class>
- </Classes>
- </Test>
- </Suite>
Operation Result:
[HTML]View PlainCopy
- Method1 runs after me ...
- I am depended on serverstartedok ...
- Passed:serverstartedok
- PASSED: method1
- ===============================================
- Testngdependencies
- Tests Run:2, failures:0, skips: 0
- ===============================================
TestNG Dependency Configuration base usage (single method dependent)------testng dependencies (i)