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

Test events were not received

Boa tarde, estava reproduzindo o código como o instrutor no vídeo e em um primeiro momento esperava que o teste getMaiorLance() gerasse uma falha pelo delta, entretanto o teste passou sem acusar falhas nele e sim com a mensagem "Test events were not received", tentei escrever o método diretamente no código como no vídeo mas não funcionou. O primeiro código testeGetDescricao() que foi gerado no momento de criação da classe funcionou.

Código de teste:

public class LeilaoTest extends TestCase {

    @Test
    public void testGetDescricao() {
        Leilao console = new Leilao("console");
        String descricao = console.getDescricao();
        assertEquals("console", descricao);
    }

    @Test
    public void getMaiorLance(){
        Leilao console = new Leilao("console");
        Lance l1 = new Lance(new Usuario("Bia"), 200.0);
        Lance l2 = new Lance(new Usuario("Jo"), 100.0);
        Lance l3 = new Lance(new Usuario("Gui"), 400.0);
        double maiorLance = console.getMaiorLance();
        assertEquals(400.0, maiorLance, 399.9999999);
    }
}

Mensagem de erro:

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:testDebugUnitTest'.
> No tests found for given includes: [br.com.msmlabs.tdd_leilao.model.LeilaoTest.getMaiorLance](filter.includeTestsMatching)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 3s
16 actionable tasks: 2 executed, 14 up-to-date
15:19:55: Task execution finished ':app:testDebugUnitTest --tests "br.com.msmlabs.tdd_leilao.model.LeilaoTest.getMaiorLance"'.
2 respostas
solução!

Oi Beatriz, tudo bem ?

Estou estranhando esse TestCase ai da sua classe, acredito que o instrutor não use isso, tenta tirar e ve se soluciona o problema.

Funcionou, quando criei a classe de testes ela já veio estendendo o TestCase, no caso o programa estava usando o assertEquals dela, e não o método estático assertEquals.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software