Use an object in other methods of a test class

Minu :

I have a test class in Android test package. There is a class that I've create an object in it. But other method of this test class can not use this object and can not recognize the result of that method. Why and what should I do? I used static too but can't...

@RunWith(AndroidJUnit4.class)
    public class PatientDaoTest {
    private static int newRowId;
    public static PatientRecordEntity newPatient1;


    public void generationRecord(){
        newRowId = 0;
        PatientRecordEntity newPatient1 = new PatientRecordEntity();
        newPatient1.setPatient_db_ID("23456");
        newPatient1.setPatient_race("Chines");
        newRowId = (int) patientDao.addNewPatient(newPatient1);
        newPatient1.setPid(newRowId);
    }

    @Test
    public void addNewPatient() throws Exception {
        boolean pin = false;

        if (0 != newRowId) {
        pin = true;
    }

    assertTrue("addNewPatient is not true", pin);
    }
呼延十 :

use the annotation @Before.

like:

public class HTest {

    public static Integer i;

    @Before
    public void before(){
        i = 10;
    }

    @Test
    public void print() {
        System.out.println(i);
    }
}

This before method will be executed before print and i will be Initialized.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=155827&siteId=1
Recommended