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

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

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

@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("test")
/**
 * Class responsible for repository testing
 * @author Cleiton
 *
 */
public class CustomerRepositoryTests {

    private static final String EXISTANT_EMAIL = "patricia.pilar@uol.com.br";
    private static final String MISSING_EMAIL = "maurice.dolly@ie.com";
    private static final String EXISTANT_EXTERNAL_ID = "abcT10@#";
    private static final String MISSING_EXTERNAL_ID = "SD2sdc13$";
    private static final Long EXISTANT_CUSTOMER_ID = 7L;
    private static final Long NON_EXISTANT_CUSTOMER_ID = 12000L;

    @Autowired
    private CustomerRepository repository;

    /**
     * Method responsible for check if repository if able to find a stored email
     */
    @Test
    public void findCustomerByEmailOkTest() {
        Optional<CustomerEntity> customer = Optional.ofNullable(repository.findCustomerByEmail(EXISTANT_EMAIL));
        assertTrue(customer.isPresent());
    }

我的第二节课

@RunWith(SpringRunner.class)
@ExtendWith(MockitoExtension.class)
@SpringBootTest
@ActiveProfiles("test")
public class CustomerOperationsTest {

    private static final String DUPLICATED_NAME = "Marta";

    private static final String DUPLICATED_SURNAME = "Gum";

    private static final String DUPLICATED_PASSWORD = "figL@456";

    private static final String DUPLICATED_EMAIL = "gum_marta@pt.com";

    private static final String DISTINCT_EMAIL = "gum_alternative@pt.com";

    @Autowired
    private CustomerOperations service;

    @Test(expected = EmailAlreadyRegisteredException.class)
    public void verifyEmailDuplicatedOnCreateUserTest() {
        CustomerInputDTO input = createDuplicatedUser();
        service.createCustomer(input);
    }

    @Test
    public void createNewUserTest() {
        CustomerInputDTO input = createDuplicatedUser();
        input.setEmail(DISTINCT_EMAIL);
        CustomerOutputDTO dto = service.createCustomer(input);
        assertTrue(dto != null);
    }

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

WebMvcTest
@ActiveProfiles(value = "webtest")
@AutoConfigureTestDatabase
public class MoneySaverControllerTests {

    private static final String EMAIL = "defaultUser@email.com";

    private static final String NAME = "daniel";

    private static final String SURNAME = "houston";

    private static final String PASSWORD =  "b76lG@23";

    private static final String MISSING_AT_EMAIL = "fulanoemail.com";

    private static final String MISSING_SUFFIX_EMAIL = "fulano@email";

    private static final String INVALID_EMAIL_ERROR_ID = "customer.input.email.invalid";

    private static final String NAME_MAX_LENGTH_ERROR_ID = "customer.input.name.maxlength";

    private static final String SURNAME_MAX_LENGTH_ERROR_ID = "customer.input.name.maxlength";

    private static final String NAME_NOT_BLANK_ERROR_ID = "customer.input.name.notblank";
    private static final String SURNAME_NOT_BLANK_ERROR_ID = "customer.input.surname.notblank";
    private static final String EMAIL_NOT_BLANK_ERROR_ID = "customer.input.email.notblank";
    private static final String PASSWORD_NOT_BLANK_ERROR_ID = "customer.input.password.notblank";

    private static final String LONGER_USER_NAME = "MY NAME IS REALLY HUGE. I AM TOTALLY SURE ABOUT IT";

    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 ?";

    private static final String BLANK_STRING = " ";

    @Autowired
    private MockMvc mockMvc;

    @Autowired
    private ObjectMapper mapper;

    @MockBean
    private PostOfficer po;

    @MockBean
    private CustomerOperations customerOperations;

    @MockBean
    private CustomerIOConverter converter;

    @MockBean
    private DataSource dataSource;

    @Test
    public void createUserWithAllFieldsFilledTest() throws JsonProcessingException, Exception {

        CustomerInputDTO input = getFilledCustomerInputDTO();       

       mockMvc.perform(post("/customer")
            .contentType("application/json")
            .content(mapper.writeValueAsString(input)))
            .andExpect(status().isOk());
    }

我的applicationcontexttestclass

@RunWith(Suite.class)
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
@ActiveProfiles({"test", "webtest"}) 
@Suite.SuiteClasses(value = { CustomerOperationsTest.class,MoneySaverControllerTests.class,CustomerRepositoryTests.class })
public class MoneySaverApplicationTests {

    @Test
    public void contextLoads() {
    }

}

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

暂无答案!

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

相关问题