2

My test case looks something like this:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
public class AbstractDatabaseTestCase extends AbstractTestCase {

    @Autowired
    private SessionFactory sessionFactory;

}

For some reason when I run it locally on my computer either through Eclipse (using Junit4 test runner) or using ant (both in eclipse, or just in terminal), everything works fine and the sessionFactory gets injected correctly.

When this code is on a server (Hudson), either running it through Hudson or in the console by doing ant test (test is the target to build and run the junit tests), the sessionFactory isn't injected and it looks like Autowiring isn't working. I looked at the stack trace from the nullpointerexception and noticed that it isn't using the SpringJUnit4ClassRunner even though i have it in the @RunWith annotation (on my local computer it does use it). Any ideas why? I guess it's not autowiring because it's not using SpringJUnit4ClassRunner.

Thanks

skaffman
  • 398,947
  • 96
  • 818
  • 769
czer
  • 676
  • 3
  • 8
  • 20
  • 1
    when i set the classpath in unix through the console to my application's lib folder and classes folder, and run the junit test as so, without ant, everything works fine: java org.junit.runner.JUnitCore com.company.dao.SomeTest – czer Apr 13 '11 at 00:52
  • 3
    I found that the difference is between using ant 1.8.1 and ant 1.8.2. It works fine in 1.8.1 but in 1.8.2 it looks like it's not seeing the @RunWith and using the SpringJunit4ClassRunner. I removed the ant-junit.jar and ant-junit4.jar from the lib folder in 1.8.2 and copied the ant-junit.jar from 1.8.1 into the lib of 1.8.2 and everything works fine now. Is there something different in the 1.8.2 of the ant junit tasks that i need to change when running my unit tests? Thanks – czer Apr 13 '11 at 16:08
  • Check your ant configuration. I noticed in the Ant JUnit documentation (http://ant.apache.org/manual/Tasks/junit.html) that the attribute was introduced and is required. You may need to specify which test cases should run. – climmunk Apr 22 '11 at 03:12

0 Answers0