0
私のユニットテストでは常にヌルログインサービスを受け取りました。 はxml構成でautowiringなしでspringを使用していました。JUnit Spring with xml NoアノテーションでBeanをロードできません
junitのテストとは別に、tomcatを実行してもエラーは発生しませんでした。
私はJUnitの-4.12、hamcrestライブラリ-1.3、hamcrestコア-1.3
<util:properties location="classpath:user-credentials.properties" id="userCredentials"` />
<bean id="loginServiceBean" class="com.company.service.LoginService">
<property name="userCredentials" ref="userCredentials" />
</bean>
私のJUnitテストで
@ContextConfiguration("classpath:WEB-INF/beans.xml")
public class LoginServiceTest {
private LoginService loginService;
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void loginTest() {
User user = createUserModel();
try {
loginService.login(user);
} catch (LoginException e) {
fail(e.getMessage());
}
}
private User createUserModel() {
User user = new User();
user.setName("user");
user.setPassword("pass");
return user;
}
public LoginService getLoginService() {
return loginService;
}
public void setLoginService(LoginService loginService) {
this.loginService = loginService;
}
}
'loginService'が初期化されていません – Danh