【发布时间】:2016-07-14 23:37:59
【问题描述】:
在 build.gradle 中
dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
}
代码
import com.myapp.LVActivity;
import org.junit.Test;
import static org.junit.Assert.*;
public class DeviceUnitTest {
@Test
public void check_that_is_correct_device_name_isTrue() {
assertThat(LVActivity.isCorrectDevice("MySpecialDevice"), is(true));
}
}
在 LVActivity 中:
private final static String correctName = "MySpecialDevice";
public static boolean isCorrectDevice(String deviceName) {
return deviceName.equals(correctName);
}
错误在这里:
is(true)
错误:
Cannot resolve method is(boolean)
我正在尝试做一个简单的本地单元测试。
我正在关注这个教程http://developer.android.com/training/testing/unit-testing/local-unit-tests.html
【问题讨论】:
-
您需要静态导入
Matchers.is或完全限定调用以说明您要使用Matchers类中的is方法。 -
这个问题节省了我的时间..谢谢
标签: android unit-testing junit boolean local