gpt4 book ai didi

java - 房间仪器测试

转载 作者:行者123 更新时间:2023-12-02 09:50:41 26 4
gpt4 key购买 nike

“我有一个房间数据库,它工作正常,我现在想测试它,但我的测试不起作用,并且在运行时我没有看到任何断言。在此代码中,我添加一条新记录并初始化它,然后断言是否添加了记录”

@RunWith(AndroidJUnit4.class)
public class PatientDaoTest {
private PatientDao patientDao;
private PatientDatabase db;
public int patient_db_ID;
public int bed_number;

@Before
public void createDb(){
Context context = ApplicationProvider.getApplicationContext();
db = Room.inMemoryDatabaseBuilder(context, PatientDatabase.class).buil();
patientDao = db.patientDao();}

@After
public void closeDb() throws IOException {
db.close();
}


@Test
public void InsertNewPatient() throws Exception {
PatientRecordEntity newPatient = new PatientRecordEntity();
newPatient.setPatient_db_ID("123456");
newPatient.setPatient_race("chines");
newPatient.setBed_number("123");
newPatient.setReal_bed_number("1234");
newPatient.setRegister_date("5/28/2019");
newPatient.setRegister_time("3:35:02");
newPatient.setPatient_age(12);
newPatient.setPatient_gender(1);

boolean pin = false;
int newRowId = 0;
newRowId = (int) db.patientDao().addNewPatient(newPatient);
if(newRowId == 0){
pin= true;
}

assertTrue("test is true",pin);
}}

“这是我的 Dao 查询:”

@Insert
long addNewPatient(PatientRecordEntity newPatient);

“这就是使用 dao 查询的函数。我不知道我的 @test 是否为真”

public static int AddPatientToDB() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
String formatedDate = sdf.format(new Date());
sdf = new SimpleDateFormat("HH-mm-ssZ", Locale.getDefault());
String formatedTime = sdf.format(new Date());
PatientRecordEntity newPatient = new PatientRecordEntity();
newPatient.setBed_number(bed_no);
newPatient.setPatient_db_ID(patient_id);
newPatient.setRegister_time(formatedTime);
newPatient.setRegister_date(formatedDate);
int newRowId = 0;
newRowId = (int) pDatabase.patientDao().addNewPatient(newPatient);
current_patient_record_entity = newPatient;
current_patient_record_entity.pid = newRowId;
current_patient_record_entity.sessionID = Repo.currentSessionID;
current_wound_record_entity = new WoundRecordEntity();
current_wound_record_entity.patient_key = (int) newRowId;
current_sample_no = newRowId;

return newRowId;
}

最佳答案

您有 3 种选择来运行测试

1) 在菜单中运行 -> 运行 -> 选择您的测试而不是应用程序

2) Alt + Shift + F10。它将打开运行菜单

3)在此菜单中单击您的测试

enter image description here

如果您想运行 your_project 的所有测试,请右键单击“test”或“androidTest”文件夹,然后选择在“your_project”中运行测试

关于java - 房间仪器测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56338287/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com