Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

ERRO de teste ignorado

Todos os meus testes estão sendo ignorados e não estou conseguindo identificar onde é o erro! Esse particularmente é testando o repository: package clin.dan.api.Features.DoctorFeatures;

import clin.dan.api.AddressDataDTO; import clin.dan.api.Features.Consultation.ConsultationModel; import clin.dan.api.Features.DoctorFeatures.DoctorDTOs.InsertDoctorDTO; import clin.dan.api.Features.PatientFeatures.PatientDTO.PatientRegistrationDTO; import clin.dan.api.Features.PatientFeatures.PatientModel; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; import org.springframework.test.context.ActiveProfiles;

import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.TemporalAdjusters;

import static org.assertj.core.api.Assertions.assertThat;

@DataJpaTest @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) @ActiveProfiles("test") class DoctorRepositoryTest {

@Autowired
private DoctorRepository doctorRepository;

@Autowired
private TestEntityManager testEntityManager;

private AddressDataDTO setAddress(String street, String neighbourhood, String cep, String city, String uf, String number, String complement){
    return new AddressDataDTO(street, neighbourhood, cep, city, uf, number, complement);
}

private DoctorModel registerDoctor(String name, String email, String phoneNumber, String crm, Specialty specialty, AddressDataDTO address){
    var doctor = new DoctorModel(new InsertDoctorDTO(name, email, phoneNumber, crm, specialty, address));

    testEntityManager.persist(doctor);

    return doctor;
}

private PatientModel registerPatient(String name, String email, String phoneNumber, String cpf, AddressDataDTO address){
    var patient = new PatientModel(new PatientRegistrationDTO(name,email, phoneNumber, cpf, address));

    testEntityManager.persist(patient);

    return patient;
}

private void registerConsultation(DoctorModel doctor, PatientModel patient, LocalDateTime date){
    testEntityManager.persist(new ConsultationModel(null, doctor, patient, date, null));
}


@Test
@DisplayName("It should return null when the registered doctor isn't available at the date.")
void chooseRandomFreeDoctorInTheDateFirstScenery() {
    var nextMondayAtTen = LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.MONDAY)).atTime(10,0);

    var doctor = registerDoctor("doctor test 1", "doctortest1@gmail.com", "92999999999", "123445", Specialty.CARDIOLOGIA, setAddress("rua1", "bairro1", "11111-111", "manaus", "AM", "1", "test complement 1"));
    var patient = registerPatient("patient test 1", "patienttest1@gmail.com", "92999999999", "123456", setAddress("rua1", "bairro1", "11111-111", "manaus", "AM", "1", "test complement 1"));
    registerConsultation(doctor, patient, nextMondayAtTen);
    var freeDoctor = doctorRepository.chooseRandomFreeDoctorInTheDate(Specialty.CARDIOLOGIA, nextMondayAtTen);
    assertThat(freeDoctor).isNull();
}

@Test
@DisplayName("Return the doctor when the he is available at the date.")
void chooseRandomFreeDoctorInTheDateSecondScenery() {
    var nextMondayAtTen = LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.MONDAY)).atTime(10,0);

    var doctor = registerDoctor("doctor test 1", "doctortest1@gmail.com", "92999999999", "123445", Specialty.CARDIOLOGIA, setAddress("rua1", "bairro1", "11111-111", "manaus", "AM", "1", "test complement 1"));

    var freeDoctor = doctorRepository.chooseRandomFreeDoctorInTheDate(Specialty.CARDIOLOGIA, nextMondayAtTen);
    assertThat(freeDoctor).isEqualTo(doctor);
}

} 19:53:29.090 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [clin.dan.api.Features.DoctorFeatures.DoctorRepositoryTest]: DoctorRepositoryTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration. 19:53:29.312 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration clin.dan.api.ApiApplication for test class clin.dan.api.Features.DoctorFeatures.DoctorRepositoryTest

Test ignored. Test ignored. java.lang.NoSuchMethodError: 'org.junit.jupiter.api.extension.ExecutableInvoker org.junit.jupiter.api.extension.ExtensionContext.getExecutableInvoker()' at org.springframework.test.context.junit.jupiter.SpringExtension.registerMethodInvoker

https://github.com/danilobsilv/Clin

2 respostas
solução!

Oi!

Provavel que seja problema relacionado com versão de bibliotecas de testes.

O spring boot tem essa dependência para os testes:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

E ela já inclui o JUnit e Mockito nas versões corretas para a versão do Spring Boot do projeto. Mas no seu projeto você incluiu manualmente as bibliotecas do JUnit e Mockito, sendo que isso deve estar causando conflitos:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.7.0</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.7.0</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <version>3.3.3</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-junit-jupiter</artifactId>
    <version>3.11.2</version>
    <scope>test</scope>
</dependency>

Apague essas dependências, deixando apenas a do Spring, e veja se resolve.

Era isso mesmo, obrigado!