1

Maven is unable to successfully run my JUnit tests though they are being run without any problem on my Eclipse. I'm unable to solve it from the debug messages.

It is probably something to do with the Spring config because my other JUnit tests not relying on Spring are working fine.

Adding the surefire plugin forkMode as Always didn't work either.

Maven output

mvn install ... ... [INFO] --- maven-surefire-plugin:2.10:test (default-test) @ AppServer --- [INFO] Surefire report directory: C:..\surefire-reports

Running com.ws.impl.BrowserServiceImplTest Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec <<< FAILURE!

Failed tests: com.ws.impl.BrowserServiceImplTest.testGetStatuses()
com.ws.impl.BrowserServiceImplTest.testGetSellers()

Test class

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:test-context.xml")
public class BrowserServiceImplTest {

    @Autowired
    private BrowserServiceImpl browserServiceImpl;

    @Test
    public void testGetStatuses() {
        // test code
    }
        // more code
}

Surefire report

<failure type="java.lang.NullPointerException">java.lang.NullPointerException
    at com.ws.impl.BrowserServiceImplTest.testGetStatuses(BrowserServiceImplTest.java:48)
</failure>

Edit

Lines 48-49

List<String> statuses = browserServiceImpl.getStatuses();
assertEquals(12, statuses.size());

Edit 2

test-context.xml

<bean id="browserSvc" class="com.ws.impl.BrowserServiceImpl">
    <property name="filterOptionsService" ref="filterOptionsService" />
</bean>

BrowserServiceImpl.java

@WebService(targetNamespace = "http://abc.def.com", portName = "BrowserPort", serviceName = "BrowserService")
public class BrowserServiceImpl implements BrowserService {

    private FilterOptionsService filterOptionsService;

        // more code
}
Community
  • 1
  • 1
mauryat
  • 1,610
  • 5
  • 29
  • 53
  • It would probly help if you showed us line 48 of BrowserServiceImplTest – Uncle Iroh Mar 28 '13 at 18:45
  • If it is your spring object, then yes, it's obviously not loading your spring config. – Uncle Iroh Mar 28 '13 at 18:45
  • @ContextConfiguration(locations = {"/application-context.xml"}) – Uncle Iroh Mar 28 '13 at 18:46
  • Yeah, looks like your bean isn't getting autoLoaded. You say the same test runs fine though from within eclipse? – Uncle Iroh Mar 28 '13 at 20:27
  • @UncleIroh Yes, it runs fine from within eclipse. – mauryat Mar 28 '13 at 20:28
  • Did you try replacing "classpath:test-context.xml" with "/test-context.xml"? – Uncle Iroh Mar 28 '13 at 20:30
  • @UncleIroh It fails with both `@ContextConfiguration("/test-context.xml")`, `@ContextConfiguration(locations={"/test-context.xml"})` – mauryat Mar 28 '13 at 20:40
  • Your test-context.xml probably don't define a bean for `BrowserServiceImpl` . Note that usually the field is an interface (i.e. probably `BrowserService`). Why is it working in eclipse ??? no idea... maybe a bug in eclipse. – ben75 Mar 29 '13 at 10:35
  • @ben75 see Edit 2. I do have a bean for BrowserServiceImpl. – mauryat Mar 29 '13 at 17:42
  • Where does `test-context.xml` reside? Since you're using Maven, it must reside in `src/test/resources/test-context.xml`; otherwise, it will not be visible as a classpath resource for your tests when running the Maven build. – Sam Brannen Mar 30 '13 at 14:18
  • @SamBrannen Yes, it resides in `src/test/resources/` – mauryat Apr 01 '13 at 17:48
  • Can you provide the full stack trace? Also, have you verified that the `SpringJUnit4ClassRunner` is actually being used to run the test (e.g., via log output)? – Sam Brannen Jun 26 '13 at 16:58

0 Answers0