मैं Java & JUnit
पर नया हूं और विभिन्न फिक्स्चर पर आया हूं। मैंने नेट पर बहुत कुछ खोजा लेकिन मुझे जवाब नहीं मिला।क्या जुनीट में प्रत्येक टेस्ट केस के लिए अलग @Before @After का उपयोग करना संभव है?
JUnit
में विभिन्न परीक्षण केस के लिए अलग-अलग @Before @After
का उपयोग करना संभव है? उदाहरण के लिए: मैं टीसी उसके बाद निम्न test1
import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
public class testJUnit {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.out.println("Before Class");
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
System.out.println("Tear Down After Class");
}
@Before
public void setUp() throws Exception {
System.out.println("Setup");
}
@After
public void tearDown() throws Exception {
System.out.println("Tear Down");
}
@Test
public void test() {
int a = 1;
assertEquals("Testing...", 1, a);
}
@Ignore
@Test
public void test1() {
int a = 156;
assertEquals("Testing...", 156, a);
}
}
के लिए परीक्षण & अलग @Before
के लिए अलग @Before
किसी को भी मेरा मार्गदर्शन कर सकते हैं उपयोग करने के लिए यह संभव है है?
शायद आपके परीक्षण एक ही कक्षा में नहीं होनी चाहिए यदि वे समान प्रारंभिक/संदर्भ साझा नहीं करते हैं ... – LaurentG
@LaurentG OK। धन्यवाद! बीटीडब्ल्यू, क्या आप जानते हैं कि जुनीट के लिए 'मुख्य' कहां लगाया जाता है क्योंकि मुझे कोड में नहीं मिल रहा है। क्या यह जूनिट पैकेज के तहत किया जाता है? – Amrit
जुनीट परीक्षणों में 'मुख्य' नहीं है। उन्हें सीधे विकास पर्यावरण से बुलाया जाता है - कुछ कक्षा या पैकेज पर राइट-क्लिक करना और "रन परीक्षण" या मेनू में कहीं भी चयन करना; विशिष्ट आईडीई पर निर्भर करता है। आपके द्वारा प्रदान किया गया कोड पर्याप्त है, इसे और तरीकों की आवश्यकता नहीं है। आप क्या उपयोग करते हैं: ग्रहण, नेटबीन, ...? –