I've recently started developing a simple Spring/Hibernate service but i'm still quite the noob at it, I'm having a persistent issue with this particular test. Everything else seems to be working fine, but I still don't know if it's this piece of code or some misconfig.
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { SPRING_CONFIG_FILE, SPRING_CONFIG_TEST_FILE }) @Transactional public class TestManageService { @Autowired private ManageService manageService; @Test public void testCreateAndFindUser() throws InstanceNotFoundException{ User user = manageService.createUser(new User("testUser", "testPass", "admin")); User foundUser = manageService.findUser(user.getUserId()); assertEquals(user, foundUser); } } Line 28 is
User user = manageService.createUser(new User("testUser", "testPass", "admin")); Running this in Eclipse results in JUnit complaining bout No Runable Methods, running mvn test results in surefire reporting the following
<test-method status="FAIL" signature="testCreateAndFindUser()" name="testCreateAndFindUser" duration-ms="6" started-at="2014-07-18T04:34:53Z" finished-at="2014-07-18T04:34:53Z"> <exception class="java.lang.NullPointerException"> <full-stacktrace> <![CDATA[java.lang.NullPointerException at com.viktortech.automaton.test.model.manageservice.TestManageService.testCreateAndFindUser(TestManageService.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74) ..... ..... I'm sure this is a trivial problem that I just can't solve because of my short experience with these frameworks. If you need any other file content for solving this issue, just ask away please. Hope you can help and thanks in advance.
Following some Comments' Requests about the ContextConfiguration, this is in the imports of TestManageService
import static com.viktortech.automaton.model.util.GlobalNames.SPRING_CONFIG_FILE; import static com.viktortech.automaton.test.util.GlobalNames.SPRING_CONFIG_TEST_FILE; Those lead to two similar files (One for Main and another for Test)
package com.viktortech.automaton.test.util; public final class GlobalNames { public static final String SPRING_CONFIG_TEST_FILE = "classpath:/automaton-spring-config-test.xml"; private GlobalNames () {} } I'm adding a Dropbox link to a copy to the the HEAD version of the project's source folder so you can check whatever you need to sort this out. Sorry for not doing this earlier https://www.dropbox.com/sh/wqqghvyoz49ue4y/AABSDrDKtwLIlqT6vUVmehv4a
User user = manageService.createUser(new User("testUser", "testPass", "admin"));manageServiceis null, which will be because@Autowireddid not work.