在测试的其他方法中使用对象 class

Use an object in other methods of a test class

我在 Android 测试包中有一个测试 class。我在其中创建了一个对象 class。但是这个测试的其他方法 class 不能使用这个对象并且不能识别那个方法的结果。为什么以及我应该做什么?我也用了 static 但不能...

@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);
    }

使用注解@Before.

喜欢:

public class HTest {

    public static Integer i;

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

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

before方法将在printi初始化之前执行。