在特定存储库上使用MockMvc进行春季测试

时间:2020-02-06 18:47:36

标签: java spring unit-testing testing junit

我正在尝试使用MockMvc对我的spring-boot应用程序进行测试,由于这是我的新手,所以我什至不确定我们的测试布局是否正确。我们有_movie个存储库,以及每个存储库的一个控制器。我们的测试安排如下:

Rental

我的应用程序具有多个存储库:

n

每个测试类使用与要测试的控制器相同的存储库。然而。我遇到一个@RunWith(SpringRunner.class) @WebMvcTest(controllers = Repo1Controller.class) public class Repo1ControllerTest { @Autowired private MockMvc mockMvc; @MockBean private Repo1Repository repository; //.... Tests and such } @RunWith(SpringRunner.class) @WebMvcTest(controllers = Repo2Controller.class) public class Repo2ControllerTest { @Autowired private MockMvc mockMvc; @MockBean private Repo2Repository repository; //.... Tests and such } 错误,第一个测试类抱怨没有bean可用于repo2repository,第二个测试类抱怨没有bean可用于repo1repository。

我想知道是否有一种方法可以使MockMvc忽略它未使用的存储库的存在?我尝试使用public interface Repo1 extends JpaRepository<Type1, Long> { //Don't need anything in here } public interface Repo2 extends JpaRepository<Type2, Long> { //Don't need anything here either } ,但这不能解决问题。

0 个答案:

没有答案