Simple Method dependency for testng dependency test. Use the dependsonmethods attribute to configure the dependency method.
Java code:
/***** <P> * Title: testngdependencies * </P> ** <p> * Description: testng provides two dependency implementations ** 1. mandatory dependency: if one of the dependency chains to be executed before a test case fails, all subsequent tests will not be executed * 2. sequential dependency (soft dependency): it is used to detect whether a test chain is executed in the correct order, even if one of the test cases fails to be executed, but it will not affect the execution of the entire test chain * dependsonmethods * (if the dependent method has multiple overloaded methods, all the overloaded methods will be executed. If you only want to execute one method, use dependsongroups) * </P> ** <p> * company: * </P> ** @ Author: Dragon ** @ Date: october 13, 2014 */public class testngdependencies {@ testpublic 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:
<?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>
Running result:
method1 runs after me......I am depended on serverStartedOk......PASSED: serverStartedOkPASSED: method1=============================================== TestngDependencies Tests run: 2, Failures: 0, Skips: 0===============================================
Testng dependency description (ii) ----- mandatory dependency and sequential dependency
If I am sincere,
Don't say it to me. Because I understand,
You are responsible for coping against your inception, and loyal words against your ears.
Testng dependency description (1) ------ simple dependency (single method dependency)