I want to test shut down and switch on information in junit.
public void shutDownState(Context cxt) {
Log.d(TAG, "in shutdown fun");
SimpleDateFormat sdfDateTime1 = new SimpleDateFormat(
"yy-MM-dd HH:mm:ss", Locale.US);
shutDownTime = sdfDateTime1.format(System.currentTimeMillis());
try {
long swithchoffdata;
if (!"00:00:00.000".equals(dsd.getLastRecord())) {
swithchoffdata = dsd.insert(shutDownTime.toString(),
switchOnTime);
Log.d(TAG, "switchoffdata: " + swithchoffdata);
}
} catch (NullPointerException ne) {
ne.printStackTrace();
Log.d(TAG, "Swithch off error: ");
}
Log.d(TAG, "swith off: " + dsd.selectAll());
}
public void swithOnState() {
Log.d("appcheck", "switch on func");
SimpleDateFormat sdfDateTime1 = new SimpleDateFormat(
"yy-MM-dd HH:mm:ss", Locale.US);
switchOnTime = sdfDateTime1.format(System.currentTimeMillis());
dsd.updateLastRecord(switchOnTime);
Log.d("appcheck", "switch on: " + dsd.selectAll());
}
These are my methods in actual project. What I should do actually in my test class to unit test this methods. Please help me out. Thanks in advance.
Here is a template that might work. There are a lot of unanswered questions about your code. Are these methods in an
Activity, for example? I assume so. I recommend theAndroidTestCaseas it doesn’t launch the activity and so consumes much less overhead and runs faster. TheAndroidTestCaseprovides anmContextmember variable so that you can pass the context to yourshutDownState()method.You can check your class member variables (such as
switchOnTime) using asserts after the call.Hope this helps.