簡體   English   中英

在測試類的其他方法中使用對象

[英]Use an object in other methods of a test class

我在 Android 測試包中有一個測試類。 有一個類,我在其中創建了一個對象。 但是這個測試類的其他方法不能使用這個對象,也不能識別那個方法的結果。 為什么以及我應該怎么做? 我也使用了靜態,但不能...

@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方法將在print before執行並且i將被初始化。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM