I want to be able to split a large test into smaller tests, so when smaller tests pass, they imply that a large test will also pass (so there is no reason to run the original large test). I want to do this because smaller tests usually take less time, less effort and less fragile. I would like to know if there are test design patterns or validation tools that can help me achieve this test splitting in a reliable way.
I am afraid that the connection between smaller tests and the original test will be lost if someone changes something in the set of smaller tests. Another concern is that a set of small tests does not actually cover a large test.
An example of what I'm aiming for:
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){ .. }
..
}
class B {
public Output process(InputFromA i){ .. }
..
}
@Test
public void theBigTest(){
A systemUnderTest = createSystemUnderTest();
Input i = createInput();
Output o = systemUnderTest.process(i);
assertEquals(o, expectedOutput());
}
@PartlyDefines("theBigTest")
@Test
public void smallerTest1(){
Input i = createInput();
InputFromA x = expectedInputFromA();
Output expected = expectedOutput();
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")
@Test
public void smallerTest2(){
InputFromA x = expectedInputFromA();
Output expected = expectedOutput();
B classUnderTest = createInstanceOfClassB();
Output o = classUnderTest.process(x);
assertEquals(o, expected);
}