spring:suitclasses能够在suit中运行webmvctest吗?

s4chpxco  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(200)

我开始测试我的springweb应用程序(restmicroservice),我有三个不同的测试类
存储库测试
服务层测试
web层测试
前两个运行整个上下文应用程序,而第三个只运行测试web层所需的方面。我的意图是在编译阶段执行所有这些类,但即使使用@suitclasses注解,唯一拒绝初始化的类就是web层测试类。
你知道发生了什么事吗?
我的第一节课

  1. @RunWith(SpringRunner.class)
  2. @SpringBootTest
  3. @ActiveProfiles("test")
  4. /**
  5. * Class responsible for repository testing
  6. * @author Cleiton
  7. *
  8. */
  9. public class CustomerRepositoryTests {
  10. private static final String EXISTANT_EMAIL = "patricia.pilar@uol.com.br";
  11. private static final String MISSING_EMAIL = "maurice.dolly@ie.com";
  12. private static final String EXISTANT_EXTERNAL_ID = "abcT10@#";
  13. private static final String MISSING_EXTERNAL_ID = "SD2sdc13$";
  14. private static final Long EXISTANT_CUSTOMER_ID = 7L;
  15. private static final Long NON_EXISTANT_CUSTOMER_ID = 12000L;
  16. @Autowired
  17. private CustomerRepository repository;
  18. /**
  19. * Method responsible for check if repository if able to find a stored email
  20. */
  21. @Test
  22. public void findCustomerByEmailOkTest() {
  23. Optional<CustomerEntity> customer = Optional.ofNullable(repository.findCustomerByEmail(EXISTANT_EMAIL));
  24. assertTrue(customer.isPresent());
  25. }

我的第二节课

  1. @RunWith(SpringRunner.class)
  2. @ExtendWith(MockitoExtension.class)
  3. @SpringBootTest
  4. @ActiveProfiles("test")
  5. public class CustomerOperationsTest {
  6. private static final String DUPLICATED_NAME = "Marta";
  7. private static final String DUPLICATED_SURNAME = "Gum";
  8. private static final String DUPLICATED_PASSWORD = "figL@456";
  9. private static final String DUPLICATED_EMAIL = "gum_marta@pt.com";
  10. private static final String DISTINCT_EMAIL = "gum_alternative@pt.com";
  11. @Autowired
  12. private CustomerOperations service;
  13. @Test(expected = EmailAlreadyRegisteredException.class)
  14. public void verifyEmailDuplicatedOnCreateUserTest() {
  15. CustomerInputDTO input = createDuplicatedUser();
  16. service.createCustomer(input);
  17. }
  18. @Test
  19. public void createNewUserTest() {
  20. CustomerInputDTO input = createDuplicatedUser();
  21. input.setEmail(DISTINCT_EMAIL);
  22. CustomerOutputDTO dto = service.createCustomer(input);
  23. assertTrue(dto != null);
  24. }

我的第三节课(有问题的那节)

  1. WebMvcTest
  2. @ActiveProfiles(value = "webtest")
  3. @AutoConfigureTestDatabase
  4. public class MoneySaverControllerTests {
  5. private static final String EMAIL = "defaultUser@email.com";
  6. private static final String NAME = "daniel";
  7. private static final String SURNAME = "houston";
  8. private static final String PASSWORD = "b76lG@23";
  9. private static final String MISSING_AT_EMAIL = "fulanoemail.com";
  10. private static final String MISSING_SUFFIX_EMAIL = "fulano@email";
  11. private static final String INVALID_EMAIL_ERROR_ID = "customer.input.email.invalid";
  12. private static final String NAME_MAX_LENGTH_ERROR_ID = "customer.input.name.maxlength";
  13. private static final String SURNAME_MAX_LENGTH_ERROR_ID = "customer.input.name.maxlength";
  14. private static final String NAME_NOT_BLANK_ERROR_ID = "customer.input.name.notblank";
  15. private static final String SURNAME_NOT_BLANK_ERROR_ID = "customer.input.surname.notblank";
  16. private static final String EMAIL_NOT_BLANK_ERROR_ID = "customer.input.email.notblank";
  17. private static final String PASSWORD_NOT_BLANK_ERROR_ID = "customer.input.password.notblank";
  18. private static final String LONGER_USER_NAME = "MY NAME IS REALLY HUGE. I AM TOTALLY SURE ABOUT IT";
  19. private static final String LONGER_USER_SURNAME = "PROBABLY MY NAME IS THE LARGEST NAME IN THE WORLD,MAYBE AN OLD AND LOYAL NAME, WHAT DO YOU THINK ABOUT IT ?";
  20. private static final String BLANK_STRING = " ";
  21. @Autowired
  22. private MockMvc mockMvc;
  23. @Autowired
  24. private ObjectMapper mapper;
  25. @MockBean
  26. private PostOfficer po;
  27. @MockBean
  28. private CustomerOperations customerOperations;
  29. @MockBean
  30. private CustomerIOConverter converter;
  31. @MockBean
  32. private DataSource dataSource;
  33. @Test
  34. public void createUserWithAllFieldsFilledTest() throws JsonProcessingException, Exception {
  35. CustomerInputDTO input = getFilledCustomerInputDTO();
  36. mockMvc.perform(post("/customer")
  37. .contentType("application/json")
  38. .content(mapper.writeValueAsString(input)))
  39. .andExpect(status().isOk());
  40. }

我的applicationcontexttestclass

  1. @RunWith(Suite.class)
  2. @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
  3. @ActiveProfiles({"test", "webtest"})
  4. @Suite.SuiteClasses(value = { CustomerOperationsTest.class,MoneySaverControllerTests.class,CustomerRepositoryTests.class })
  5. public class MoneySaverApplicationTests {
  6. @Test
  7. public void contextLoads() {
  8. }
  9. }

最后。。。只有两个测试类执行测试的图片

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题