Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Erro ao rodar o primeiro teste - Banco de dados MySQL

Bom dia pessoal! Não estou conseguindo rodar o primeiro teste do curso, da classe ForumApplicationTests...método contextLoads().

package br.com.alura.forum;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class ForumApplicationTests {

    @Test
    public void contextLoads() {
        Assert.assertTrue(true);
    }
}
2020-10-07 11:53:52.793  INFO 12564 --- [           main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-10-07 11:53:52.813  INFO 12564 --- [           main] b.com.alura.forum.ForumApplicationTests  : Started ForumApplicationTests in 8.882 seconds (JVM running for 11.59)
2020-10-07 11:53:52.872 ERROR 12564 --- [gistrationTask1] o.s.s.s.TaskUtils$LoggingErrorHandler    : Unexpected error occurred in scheduled task

java.lang.IllegalStateException: couldn't determine local port. Please set spring.boot.admin.client.instance.service-base-url.
    at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.getLocalServerPort(DefaultApplicationFactory.java:189) ~[spring-boot-admin-client-2.1.4.jar:2.1.4]
    at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.getServiceBaseUrl(DefaultApplicationFactory.java:104) ~[spring-boot-admin-client-2.1.4.jar:2.1.4]
    at de.codecentric.boot.admin.client.registration.ServletApplicationFactory.getServiceUrl(ServletApplicationFactory.java:62) ~[spring-boot-admin-client-2.1.4.jar:2.1.4]
    at de.codecentric.boot.admin.client.registration.ServletApplicationFactory.getManagementBaseUrl(ServletApplicationFactory.java:77) ~[spring-boot-admin-client-2.1.4.jar:2.1.4]
    at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.getHealthUrl(DefaultApplicationFactory.java:150) ~[spring-boot-admin-client-2.1.4.jar:2.1.4]
    at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.createApplication(DefaultApplicationFactory.java:75) ~[spring-boot-admin-client-2.1.4.jar:2.1.4]
    at de.codecentric.boot.admin.client.registration.ApplicationRegistrator.createApplication(ApplicationRegistrator.java:154) ~[spring-boot-admin-client-2.1.4.jar:2.1.4]
    at de.codecentric.boot.admin.client.registration.ApplicationRegistrator.register(ApplicationRegistrator.java:71) ~[spring-boot-admin-client-2.1.4.jar:2.1.4]
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
    at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[na:na]
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
    at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
1 resposta
solução!

Pessoal, a resposta está na aula 6 deste curso (Testando o repository com outro banco de dados). Eu não estou usando o h2 e por default o Spring Boot usa ele. Para resolver o problema é necessário inserir uma anotação nas classes de teste: @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)