r1 - 08 Mar 2007 - 15:46:04 - MaxwellAlmeidaYou are here: TWiki >  Doo Web  > TecnoLogias > IntroducaoAoJUnit4
Teste simples com JUnit4

import org.junit.Test;
import junit.framework.TestCase;

public class testandoSoma extends TestCase {

    private int x = 1;
    private int y = 1;

    @Test public void testeDeSoma() {
        int resultado = x + y;
        assertEquals(2, resultado);
    }
}

Usando mais as caracteristicas do JUnit 4, o mesmo teste poderia ficar mais simples:

import static org.junit.Assert.*;
import org.junit.Test;

public class testandoSoma   {

    private int x = 1;
    private int y = 1;

    @Test public void somando() {
        int resultado = x + y;
        assertEquals(2, resultado);
    }

}

Se evitarmos o Assert do JUnit e usarmos o do Java:

import org.junit.Test;

public class testandoSoma   {

    private int x = 1;
    private int y = 1;

    @Test public void somando() {
        int resultado = x + y;
        assert (2 == resultado);
    }

}

Não é recomendado a última opção pois usar o JUnit 4 deixa o código mais coerente.
Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r1 | More topic actions
Doo.IntroducaoAoJUnit4 moved from Doo.IntroducaoAOJUnit4 on 08 Mar 2007 - 15:46 by MaxwellAlmeida - put it back
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback