2009-08-31 2 views
3

다음 테스트 클래스가 있지만 "ContextConfiguration-locations"로 설정 한 내용이 중요하지 않습니다. 내 UserService를 설정하지 않습니다. 그리고 location-property에 존재하지 않는 파일을 설정할 때 어떤 오류도 발생시키지 않습니다 ... 내가 뭘 잘못하고 있니?Spring : JUnit-test : applicationContext가로드되지 않았습니다.

@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; 
} 
} 

스프링 버전 : 2.5.6.SEC01

의 JUnit-버전 : 4.5

JDK : 테스트가 예외를 표시하지 않는 이유 1.5

+0

@Autowired를 사용할 때 속성에 대한 세터가 필요하지 않으며 왜 공용 getter가 필요한지 알지 못합니다. – crunchdog

+0

getter/setter를 제거하고 setup() - 메서드를 포함했습니다. bizzarely, setup() 메소드가 호출되지 않는 것처럼 보입니다 ... 거기에 Assert.assertNotNull (null)을 넣고 디버그 중단 점을 넣지 만 결코 거기에 도착하지 않습니다 ... – swalkner

+0

설정에 주석을 달았습니까()를 @Before 주석과 함께 사용 하시겠습니까? 그리고 스프링 주입 오류가 발생하지 않습니까? UserService Bean은 어떻게 선언되며, 게시 할 수 있습니까? – crunchdog

답변

1

아직 테스트하지는 않았지만 실제로 스프링 3.0으로 업그레이드하려면 ehcache-spring-annotations framework을 사용할 수 있습니다.

+0

http://code.google.com/p/ehcache-spring-annotations/ 또한 스프링 2.5와 호환됩니다. – Eric

관련 문제