"पहले सेस्ट" केवल एक बार मुद्रित होता है, दो बार नहीं। मैं क्या गलत कर रहा हूं?
*** क्षमा करें। मैंने यह नहीं देखा है कि आपको @BeforeTest लिखा गया है, लेकिन आपके उदाहरण में @BeforeTest लगभग @BeforeClass के बराबर है, और @BeforeClass का उपयोग करने के लिए बेहतर है, जब आपके पास अब परीक्षण कक्षाएं नहीं हैं।
@BeforeClass "एक ही कक्षा है कि अपने परीक्षण तरीकों, अलग ढंग से नहीं!
//Example
package test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class Tests {
private String bClass;
private String bMethod1;
private String bMethod2;
@BeforeClass
public void beforeClass() {
bClass = "BeforeClass was executed once for this class";
}
@BeforeMethod
public void beforeMetodTest1() {
bMethod1 = "It's before method for test1";
}
@Test
public void test1() {
System.out.println(bClass);
System.out.println(bMethod1);
}
@BeforeMethod
public void beforeMethodTest2() {
bMethod2 = "It's before method for test2";
}
@Test
public void test2() {
System.out.println(bClass);
System.out.println(bMethod2);
}
}
@BeforeClass एक बार अपने सभी परीक्षणों तरीकों से पहले इस वर्ग में मार डाला जाएगा, में घोषित किया जाना चाहिए। @BeforeMethod परीक्षा पद्धति से पहले मार डाला जाएगा , इससे पहले कि यह लिखा गया है।
@BeforeClass टेस्ट क्लास में केवल एक हो सकता है, अंतर में @BeforeMethod! (यदि यह कुछ @BeforeClass है, तो वे मोड़ से किए जाते हैं, लेकिन यह परीक्षण की सही संरचना नहीं है)
पी एस मेरे अंग्रेजी के लिए खेद है :)