मैं छोटे परीक्षणों में एक बड़े परीक्षण को विभाजित करने में सक्षम होना चाहता हूं ताकि जब छोटे परीक्षण पास हों तो उनका मतलब है कि बड़ा परीक्षण भी पास होगा (इसलिए चलाने का कोई कारण नहीं है मूल बड़ा परीक्षण)। मैं ऐसा इसलिए करना चाहता हूं क्योंकि छोटे परीक्षण आमतौर पर कम समय लेते हैं, कम प्रयास करते हैं और कम नाजुक होते हैं। मैं जानना चाहता हूं कि टेस्ट डिज़ाइन पैटर्न या सत्यापन उपकरण हैं जो इस परीक्षण को एक मजबूत तरीके से विभाजित करने में मेरी सहायता कर सकते हैं।छोटे परीक्षणों के सेट पर एक परीक्षण को विभाजित करना
मुझे डर है कि छोटे परीक्षणों और मूल परीक्षण के बीच कनेक्शन खो जाता है जब कोई छोटे परीक्षणों के सेट में कुछ बदलता है। एक और डर यह है कि छोटे परीक्षणों का सेट वास्तव में बड़े परीक्षण को कवर नहीं करता है।
मैं क्या कर रहा हूँ पर निशाना का एक उदाहरण:
//Class under test
class A {
public void setB(B b){ this.b = b; }
public Output process(Input i){
return b.process(doMyProcessing(i));
}
private InputFromA doMyProcessing(Input i){ .. }
..
}
//Another class under test
class B {
public Output process(InputFromA i){ .. }
..
}
//The Big Test
@Test
public void theBigTest(){
A systemUnderTest = createSystemUnderTest(); // <-- expect that this is expensive
Input i = createInput();
Output o = systemUnderTest.process(i); // <-- .. or expect that this is expensive
assertEquals(o, expectedOutput());
}
//The splitted tests
@PartlyDefines("theBigTest") // <-- so something like this should come from the tool..
@Test
public void smallerTest1(){
// this method is a bit too long but its just an example..
Input i = createInput();
InputFromA x = expectedInputFromA(); // this should be the same in both tests and it should be ensured somehow
Output expected = expectedOutput(); // this should be the same in both tests and it should be ensured somehow
B b = mock(B.class);
when(b.process(x)).thenReturn(expected);
A classUnderTest = createInstanceOfClassA();
classUnderTest.setB(b);
Output o = classUnderTest.process(i);
assertEquals(o, expected);
verify(b).process(x);
verifyNoMoreInteractions(b);
}
@PartlyDefines("theBigTest") // <-- so something like this should come from the tool..
@Test
public void smallerTest2(){
InputFromA x = expectedInputFromA(); // this should be the same in both tests and it should be ensured somehow
Output expected = expectedOutput(); // this should be the same in both tests and it should be ensured somehow
B classUnderTest = createInstanceOfClassB();
Output o = classUnderTest.process(x);
assertEquals(o, expected);
}
+1 एक ही कक्षा में परीक्षणों को रखना (और आपके द्वारा किए गए टेस्ट क्लास का नामकरण) इससे कम संभावना है कि कोई व्यक्ति मूल परीक्षण और छोटे परीक्षणों के बीच गलती से कनेक्शन को तोड़ देगा। इसके लिए धन्यवाद। फिर भी मुझे यह जानने का कुछ स्वचालित तरीका याद आ रहा है कि छोटे परीक्षणों का अर्थ है कि बड़ा परीक्षण पास होगा। – mkorpela
@ मकोर्पेला, क्या आप थोड़ा सा विस्तार कर सकते हैं कि छोटे परीक्षणों का अर्थ यह है कि बड़ा परीक्षण कब होगा? यदि छोटे परीक्षणों में से एक विफल रहता है, तो क्या यह इंगित करने के लिए पर्याप्त नहीं है कि कोई समस्या मौजूद है? किसी भी मामले में, अधिकांश परीक्षण धावकों को पूरे टेस्ट क्लास की स्थिति का संकेत मिलता है। उदाहरण के लिए, एनयूनीट और ग्रहण जुनीट टेस्ट धावक दोनों कक्षा वर्ग में सभी परीक्षणों को पार करते हैं, और "लाल" यदि एक और परीक्षण विफल हो जाते हैं तो परीक्षण कक्षा दोनों "हरा" के रूप में चिह्नित करते हैं। यदि सभी छोटे परीक्षण पास होते हैं तो "द बिगटेस्ट" को गुजरने के रूप में चिह्नित किया जाएगा। –
@ हर्मे, मैं मूल परीक्षण को हटा नहीं सकता अगर यह ऐसी परिस्थिति में विफल हो सकता है जहां छोटे परीक्षण पास होंगे। – mkorpela