Ejemplo 1: prueba junit de Java
import org.junit.Assert;
import org.junit.Test;
public class Test {
public static int square(int n) {
return n * n;
}
@Test
public void squareTest() {
Assert.assertEquals(25, square(5));
Assert.assertEquals(16, square(4));
Assert.assertEquals(9, square(3));
Assert.assertEquals(4, square(2));
Assert.assertEquals(1, square(1));
}
}
Ejemplo 2: anotación @test en junit
# Used in JAVA
public class Example {
@Test
public void method() {
org.junit.Assert.assertTrue( new ArrayList().isEmpty() );
}
}
Ejemplo 3: prueba junit
import junit.framework.*;
public class JavaTest extends TestCase {
protected int value1, value2;
// assigning the values
protected void setUp(){
value1 = 3;
value2 = 3;
}
// test method to add two values
public void testAdd(){
double result = value1 + value2;
assertTrue(result == 6);
}
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)