I want to write a test that perform Setup in several ways but expect them to produce the same output. Basically like
@Before
public void setUp1(){
obj.addDataThisWay(data);
}
@Before
public void setUp2(){
obj.addDataThatWay(data);
}
@Test
public void testResult(){
assertEquals(obj.getResult(),1);
}
I want it the test to run twice, one for setUp1()->testResult()
, the other one for setUp2()->testResult()
Is that possible?
Not to my knowledge. You must either turn this into two separate tests (and extract the assertions to a common, private, non-@Test
method if you want to), or you can use parameterized tests.
public void testWithSetup1() {
callSetup1Here();
.....
}
public void testWithSetup2() {
callSetup2Here();
.....
}
I don't think there is any other way to do what you are asking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With