JUnit, niepowodzenie testu

0

Kiedyś używałem JUnita do jednej metody, i naprawdę mi pomógł wychwycić błąd. Teraz chcę wypróbować najprostszy przykład, i test jest zakończony niepowdzeniem.

package test1;

/**
 *
 * @author Damian
 */
public class Test1 {

    /**
     * @param args the command line arguments
     */
    public int add(int a, int b)
    {
        return a + b;
    }
    public static void main(String[] args) {
        // TODO code application logic here
        
    }
    
}
package test1;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Damian
 */
public class Test1Test {
    
    public Test1Test() {
    }
    
    @BeforeClass
    public static void setUpClass() {
    }
    
    @AfterClass
    public static void tearDownClass() {
    }
    
    @Before
    public void setUp() {
    }
    
    @After
    public void tearDown() {
    }

    /**
     * Test of add method, of class Test1.
     */
    @Test
    public void testAdd() {
        System.out.println("add");
        int a = 0;
        int b = 0;
        Test1 instance = new Test1();
        int expResult = 0;
        int result = instance.add(a, b);
        assertEquals(expResult, result);
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
    }

    /**
     * Test of main method, of class Test1.
     */
    @Test
    public void testMain() {
        System.out.println("main");
        String[] args = null;
        Test1.main(args);
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
    }
    
}

Co robię źle?

1

Kompilujesz z fail("The test case is a prototype.");, tzn. z instrukcją fail? Ona zawsze będzie wykrzaczała Ci test z podanym powodem.

0

no tak, zapomniałem o fail.

1 użytkowników online, w tym zalogowanych: 0, gości: 1