0
我正在开发一个JUnit测试到Spring Controller中,Controller调用了一堆服务。我的JUnit测试代码是上面:在运行JUnit测试时发现空服务弹出
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {WebApplicationConfiguration.class, DatabaseConfiguration.class, ServiceConfiguration.class})
@WebAppConfiguration
public class ProcessFileControllerTest {
private MockMvc mockMvc;
@Test
public void getPageTest() throws Exception{
final ProcessFileController controller = new ProcessFileController();
SecurityHelperUtility.setupSecurityContext("user", "pass", "ROLE_ADMIN");
mockMvc = standaloneSetup(controller).build();
mockMvc.perform(get(URI.create("/processFile.html")).sessionAttr("freeTrialEmailAddress", "")).andExpect(view().name("processFile"));
}
当我运行JUnit测试中,我得到一个NullPointerExcelption
当我打电话的代码,我ProcessFileController.java
final Company company = companyService.getCompanyByUser(userName);
这一行,我可以看到, Service
是Null
。
在我ProcessFileController.java
的Service
被声明为:
@Autowired private CompanyService companyService;
任何线索?提前致谢。
工作就像一个魅力。谢谢。 –