0
JUnitテストをSpring Controllerに開発すると、Controllerは一連のサービスを呼び出します。私のJUnitテスト・コードは上記です:Springで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テストを実行すると、私は私が私のProcessFileController.java
final Company company = companyService.getCompanyByUser(userName);
のコードのこの特定の行を呼び出すときに私がいることがわかりますNullPointerExcelption
を取得しますService
はNull
です。
@Autowired private CompanyService companyService;
どれ手がかり:?私のProcessFileController.java
Service
のように宣言されて
前もって感謝します。
チャームのように働いた。ありがとう。 –