Spring: JUnit-Test: applicationContext not loaded

I have the following test class, but it doesn’t matter what I set as "Context-Oriented Locations" - it never installed my UserService. And this does not cause any error when I install a nonexistent file in properties-locations ... what am I doing wrong?

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContextTest.xml" })
public class BasicPersistenceTest {

@Autowired
private UserService userService;

@Test
public void testUserLogin() throws Exception {

    User result = userService.getUser("stefan", "walkner");

    Assert.assertNotNull(result);
}

@Test
public void testLogin() {
    User user = userService.getUser("stefan", "walkner");
    Assert.assertNull(user);
}

public UserService getUserService() {
    return userService;
}

public void setUserService(UserService userService) {
    this.userService = userService;
}
}

Spring -Version: 2.5.6.SEC01

JUnit-Version: 4.5

JDK: 1.5

+3
source share
2 answers

I don't know why your test shows no exceptions, but Spring 2.5 is not compatible with JUnit 4.5 . Either go to <Spring 3 slave milestones, or reduce JUnit to 4.4.

+5
+1

Source: https://habr.com/ru/post/1716472/


All Articles