我有一个产生线程的类和一个验证结果的测试。即使我可以在调试器中单步执行并看到它正在测试,但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);
}