खोज…


वाक्य - विन्यास

  • @ टेस्ट (समूह = {"group1", "group.regression"}, dependOnGroups = {"group2", "group3"})

TestNG समूह कॉन्फ़िगरेशन और मूल उदाहरण

समूह को Suite और / या Test तत्व के तहत कॉन्फ़िगर किया जा सकता है testng.xml । tesng.xml में शामिल किए गए सभी समूहों को निष्पादन के लिए विचार किया जाएगा, एक को छोड़कर नजरअंदाज कर दिया जाएगा। यदि @Test पद्धति में कई समूह हैं और उन समूहों से यदि किसी एकल समूह को testng.xml में बाहर रखा गया है, तो @Test पद्धति नहीं चलेगी।

नीचे समूह चलाने के लिए Test स्तर पर विशिष्ट testng.xml कॉन्फ़िगरेशन है:

<suite name="Suite World">
<test name="Test Name">
  <groups>
    <run>
      <include name="functest" />
      <exclude name="regtest" />
    </run>
  </groups>
  <classes>
    <class name="example.group.GroupTest"/>
  </classes>
</test>
</suite>

और यह परीक्षा की कक्षा कैसी होगी:

package example.group;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class GroupTest {
    
    @BeforeClass
    public void deSetup(){
        //do configuration stuff here
    }
    
    @Test(groups = { "functest", "regtest" })
    public void testMethod1() {
    }

    @Test(groups = {"functest", "regtest"} )
    public void testMethod2() {
    }

    @Test(groups = { "functest" })
    public void testMethod3() {
    }
    
    @AfterClass
    public void cleanUp(){
        //do resource release and cleanup stuff here
    }
}

इस GroupTest TestNG क्लास को चलाने पर केवल testMethod3() निष्पादित किया जाएगा।

स्पष्टीकरण:

  • <include name="functest" /> functest ग्रुप के सभी परीक्षण तरीके रन के लिए योग्य हैं यदि इसे किसी अन्य समूह द्वारा बाहर नहीं किया गया है।
  • <exclude name="regtest" /> regtest समूह की कोई भी परीक्षण विधि चलाने के लिए योग्य नहीं है।
  • testMethod1() और testMethod2() regtest समूह में हैं, इसलिए वे नहीं चलेंगे।
  • testMethod3() regtest ग्रुप में है, इसलिए यह चलेगा।

TestNG मेटाग्रुप्स - समूहों के समूह

TestNG समूहों को परिभाषित करने की अनुमति देता है जिसमें अन्य समूह शामिल हो सकते हैं। मेटाग्रुप्स तार्किक रूप से एक या एक से अधिक समूहों को @Test हैं और उन समूहों से संबंधित @Test तरीकों का निष्पादन नियंत्रित करते हैं।

नीचे दिए गए उदाहरण में विभिन्न समूह (समूहों) से संबंधित विभिन्न @Test तरीके हैं। कुछ विशेष स्टैक के लिए विशिष्ट हैं और कुछ प्रतिगमन और स्वीकृति परीक्षण हैं। यहां मेटाग्रुप बनाए जा सकते हैं। चलो कोई भी दो सरल मेटाग्रुप्स चुनें :

  1. allstack - में liux.jboss.oracle और aix.was.db2 समूह शामिल हैं और उन सभी समूहों में से किसी एक से संबंधित सभी परीक्षण विधियों को एक साथ चलाने में सक्षम बनाता है।
  2. systemtest - इसमें allstack , regression और acceptance समूह शामिल हैं और उन सभी समूहों में से किसी एक से संबंधित परीक्षण विधियों को एक साथ चलाने में सक्षम बनाता है।

testng.xml कॉन्फ़िगरेशन

<suite name="Groups of Groups">
    <test name="MetaGroups Test">
        <groups>
            <!-- allstack group includes both liux.jboss.oracle and aix.was.db2 groups -->
            <define name="allstack">
                <include name="liux.jboss.oracle" />
                <include name="aix.was.db2" />
            </define>

            <!-- systemtest group includes all groups allstack, regression and acceptance -->
            <define name="systemtest">
                <include name="allstack" />
                <include name="regression" />
                <include name="acceptance" />
            </define>

            <run>
                <include name="systemtest" />
            </run>
        </groups>

        <classes>
            <class name="example.group.MetaGroupsTest" />
        </classes>
    </test>

</suite>

मेटाग्रुप्सटेस्ट क्लास

package example.group;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class MetaGroupsTest {

    @BeforeMethod
    public void beforeMethod(){
        //before method stuffs - setup
    }

    @Test(groups = { "liux.jboss.oracle", "acceptance" })
    public void testOnLinuxJbossOracleStack() {
        //your test logic goes here
    }

    @Test(groups = {"aix.was.db2", "regression"} )
    public void testOnAixWasDb2Stack() {
        //your test logic goes here
    }

    @Test(groups = "acceptance")
    public void testAcceptance() {
        //your test logic goes here
    }

    @Test(groups = "regression")
    public void testRegression(){
        //your test logic goes here
    }

    @AfterMethod
    public void afterMthod(){
        //after method stuffs - cleanup
    }
}


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow