テストしたいSpring Batch用のファイルハンドラがあります。SpringApplication.runをどうやって模擬するのですか
SpringApplication.run()
は、渡された引数を検証したい静的メソッドです。
これはPowerMockのパスを下げる必要があることを意味しますか、これをテストするためのSpringFrameworkには何かがありますか?私は何をしないのです
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
@SpringBootTest
@PrepareForTest(SpringApplication.class)
:
public File handleFile(File file) {
// Start the Batch Process and set the inputFile parameter
String[] args = {"--inputFile=" + file.getAbsolutePath()};
SpringApplication.run(InitialFileBatchApplication.class, args);
return null;
}
私のテストクラスが動作していないようだ、次のアノテーションを持っていますか?
投げた例外は次のとおりです。
java.lang.IllegalStateException:名前org.springframework.boot.SpringApplicationでクラスを変換に失敗しました。理由:
@PrepareForTest(SpringApplication.class)
が処理されるとき、これが発生し org.springframework.web.context.support.StandardServletEnvironment
を見つけることができません。私はSpring Batchアプリケーションをテストしているので、Web環境はなく、私も追加しました。
@SpringBootTest(webEnvironment=WebEnvironment.NONE)
は、私が何をしたいのかでていますが、それはそのテスト可能なように、私は異なり、このクラスをarchitecturingする必要があることを意味するものではありません。私のテストクラスから、次の注釈がありますが、上記の例外はまだあります。 @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringRunner.class) (SpringApplication.class)@PrepareForTest @SpringBootTest(webEnvironment = WebEnvironment.NONE) @TestPropertySource(プロパティが= { "spring.batch.job.enabled = false "}) –