Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trying to understand Spring's @RunWith, @ContextConfiguration; and ANT

I'm using Spring's test annotations for the first time, and trying to understand how they fit togther. The doc says to use @RunWith to specify test runner and @ContextConfiguration to specify context config xml file. I want to run these tests through ant's JUnit task.

I read that @RunWith is a JUnit annotation, so ant's JUnit task should not have any problem processing it. But @ContextConfiguration is a Spring annotation, so how does JUnit process it? Or does Spring convert the test class into a subclass of JUnit TestCase and somehow specify the test runner? How do they actually work together?

like image 886
shrini1000 Avatar asked Oct 09 '22 08:10

shrini1000


1 Answers

By @RunWith(SpringJUnit4ClassRunner.class) you tell JUnit to use an other Runner. In this case the SpringJUnit4ClassRunner Runner. The Spring Runner then handles the @ContextConfiguration Annotation.

So it works, no matter if you start the test from Eclipse, an ohter IDE, command line, Maven or Ant.

like image 79
Ralph Avatar answered Oct 12 '22 02:10

Ralph