首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >机房仪表测试

机房仪表测试
EN

Stack Overflow用户
提问于 2019-05-28 16:45:39
回答 2查看 53关注 0票数 0

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

代码语言:javascript
复制
@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查询:”

代码语言:javascript
复制
@Insert
long addNewPatient(PatientRecordEntity newPatient);

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

代码语言:javascript
复制
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;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-05-31 11:27:21

“对于您的指南,测试是正确的,我只是修改了thanks...according:”

代码语言:javascript
复制
boolean pin = false;
int newRowId = 0;
newRowId = (int) patientDao.addNewPatient(newPatient);
newPatient.setPid(newRowId);
if(0 != newRowId){
pin= true;}
assertTrue("addNewPatient is not true",pin);

“测试通过了:))”

票数 0
EN

Stack Overflow用户

发布于 2019-05-30 15:37:46

您有3个选择来运行测试

1)在菜单中运行-> Run ->С选择测试而不是应用

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

3)点击此菜单中的测试

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56338287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档