0
スプリングブートバージョン1.5.4.RELEASE。スプリングブートユニットテスト - テスト実行中の豆がありません
アプリケーションの正常な動作は正常です。ユニットテストを実行する場合
、いくつかの豆は、たとえば、不足している:私はMongoDBのリポジトリを使用してい
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in ...service.post.PostService required a bean named 'mongoTemplate' that could not be found.
Action:
Consider defining a bean named 'mongoTemplate' in your configuration.
。私は、このBeanを返すconfigクラスを追加することでこれを解決しました。私は再びユニットテストを実行しようとしました。この後
、次のエラーが思い付いた:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in springfox.documentation.spring.data.rest.BasePathAwareServicesProvider required a bean of type 'org.springframework.data.rest.core.config.RepositoryRestConfiguration' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.data.rest.core.config.RepositoryRestConfiguration' in your configuration.
これはspringfoxを闊歩UI残りのドキュメントだけ上昇します。このアプリケーションの依存関係を削除すると、テストは正常に完了します。
私はここで何を欠席しましたか?ユニットテスト環境では、一部のBeanが見つかりません。
更新
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class ApplicationTests {
@Test
public void contextLoads() {}
}
@RunWith(SpringRunner.class)
@WebMvcTest(value = ProfileController.class, secure = false)
public class ProfileControllerTest {
private MockMvc mockMvc;
@MockBean private ProfileService profileService;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.standaloneSetup(new ProfileController(profileService)).build();
}
@Test
....
}
これは私が現在持っている唯一のテストコントローラです。
アプリケーションとテストを開始するための設定が異なるようです。 gitでアプリケーションを共有できますか?私はあなたのconfigsをチェックする必要があります、私はあなたの修正を提供することはできませんこの情報なし。あなたの設定(設定ファイル、注釈付きコンテキスト設定...)を確認することだけをお勧めします。 – Sergii
それは私的なプロジェクトですが、私は実際にテストや他の何かのための特別な構成を持っていません。ほとんどがSpring Bootで自動構成されています。テストの更新セクションを参照してください。 – xDs
テスト用のテストコンテキストをロードするには、ProfileControllerTestクラスに@SpringBootTest(classes = Application.class)というアノテーションを付ける必要があります。 –