我有一个生成线程的类和一个验证结果的测试。Emma 没有报告线程的代码覆盖率,即使我可以在调试器中单步执行并看到它正在被测试。谁能看到为什么会发生这种情况并告诉我如何解决?
产生线程的方法
private static String deviceName = DEFAULT_DEVICE_NAME;
protected void initializeDeviceName() {
if (deviceName.equals(DEFAULT_DEVICE_NAME)) {
DeviceContext.execute(new Runnable() {
@Override
public void run() {
deviceName = DeviceManager.getDeviceName();
}
});
}
}
考试
public void testGetDeviceName() {
DeviceManager.setDeviceName(DEVICE_NAME);
// constructor calls initializeDeviceName()
iconListener = new HealthIconListener(view);
sleep(SHORT_SLEEP_TIME);
assertEquals(DEVICE_NAME, HealthIconListener.getDeviceName());
}
DeviceContext中的相关方法
private static ExecutorService getExecutor() {
if (executor == null) {
executor = Executors.newCachedThreadPool();
}
return executor;
}
public static void execute(Runnable task) {
getExecutor().execute(task);
}