In my Spring-Maven project my unit tests inherit from a base class:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:testDalApplicationContext.xml" })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional(value = "transactionManager")
public abstract class BaseRepositoryUnitTest {
}
Then a tipical unit test can look like:
public class UserRepositoryTest extends BaseRepositoryUnitTest {
@Autowired
UserRepository userRepository;
@Test
public void testFindUserByEmailAddress() {
...
}
}
This structure allows me to:
- Run a single test as a Junit test (from my Eclipse IDE).
- Run all my tests using Maven build.
How do I run all my tests from my Eclipse IDE? I know I should create a test suite, but for some reason with this structure I can’t seem to figure out how.
BTW – I’m using Junit 4.9
To run all of the Junit tests within your application
Right click the Project or Package > Run as > Junit Test