I have many spring test methods in a test class. i want to run only selective tests. So i want to create a test suite in same class.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/testApplicationContext.xml"})
@TransactionConfiguration(defaultRollback=true)
public class TestersChoice {
@Test
@Transactional
public void testAddAccount(){
///do something ....
}
@Test
@Transactional
public void testDeleteAccount(){
///do something ....
}
@Test
@Transactional
public void testReadAccount(){
///do something ....
}
}
If I run this Class TestersChoice all tests will run! I just want to run testReadAccount not the rest. I want to create suite to run selective tests. (I want to avoid deleting @Test above test methods to achieve this) Something like in jUnit testcase . This is what i was able to do by extending TestersChoice class to TestCase and inserting this method:
public static TestSuite suite(){
TestSuite suite = new TestSuite();
suite.addTest(new TestersChoice("testDeleteAccount"));
return suite;
}
But as now I am not extending TestCase so I am unable to add TestersChoice instance to suite!
How to run selective tests?
if what you want is to group your tests then the issue is not with spring-test but rather with JUnit where grouping tests is not possible. Consider switching to TestNG (also supported by spring OOTB).
TestNG is built on JUnit but a lot more powerfull: See comparison.
Grouping is easy.
regards,
Stijn
You can use Spring's IfProfileValue
(if you are always using @RunWith(SpringJUnit4ClassRunner.class)
) and then tests will only run if you specify particular system properties using -D<propertyname>
.
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