05 May 2017

JUnit Test Basic vs Eclipse Java

Example 1
JUnit Test 2017
Bảng này chứ?package Test;

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

import model.Company;

public class demo {

 @Test
 public void testName(){
    Company c = new Company();
       c.setName("FPT");
       assertTrue(c.getName().equals("FPT"));
   }
 
 @Test
 public void testAddress(){
    Company c = new Company();
       c.setAddress("Hanoi");
       assertTrue(c.getAddress().equals("Hanoi"));
   }
}
Example 2
JUnit Test 2017

package Test;

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

import org.junit.BeforeClass;

import model.Company;

public class demo {

    public static Company c;

    //Khởi tạo cho tất cả
    @BeforeClass
    public static void prepareForAllTest() {
        c = new Company();
    }

    @Test
    public void testName() {
        c.setName("FPT");
        assertTrue(c.getName().equals("FPT"));
    }

    @Test
    public void testAddress() {
        c.setAddress("Hanoi");
        assertTrue(c.getAddress().equals("Hanoi"));
    }
}
Example 3
JUnit Test 2017
package Test;

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

import org.junit.Before;
import org.junit.BeforeClass;

import model.Company;

public class demo {

    public static Company c;

    @BeforeClass
    public static void prepareForAllTest() {
        c = new Company();
    }

    //Chuẩn bị cho testName
    @Before
    public void prepareTestName() {
        c.setName("FPT");
    }

    @Test
    public void testName() {
        assertTrue(c.getName().equals("FPT"));
    }

    @Test
    public void testAddress() {
        c.setAddress("Hanoi");
        assertTrue(c.getAddress().equals("Hanoi"));
    }
    @After
    public void closeTestName() {

    }

    @AfterClass
    public void closeForAllTest() {
        //Close database connect
    }
}


0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang