Adz*_*Adz 2 junit android unit-testing boolean local
在build.gradle中
dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
}
Run Code Online (Sandbox Code Playgroud)
码
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));
}
}
Run Code Online (Sandbox Code Playgroud)
在LVActivity:
private final static String correctName = "MySpecialDevice";
public static boolean isCorrectDevice(String deviceName) {
return deviceName.equals(correctName);
}
Run Code Online (Sandbox Code Playgroud)
错误在这里:
is(true)
Run Code Online (Sandbox Code Playgroud)
错误:
Cannot resolve method is(boolean)
Run Code Online (Sandbox Code Playgroud)
我正在尝试进行简单的本地单元测试.
我正在关注本教程http://developer.android.com/training/testing/unit-testing/local-unit-tests.html
你不想只说:
import static org.junit.Assert.*;
assertTrue(LVActivity.isCorrectDevice("MySpecialDevice"));
Run Code Online (Sandbox Code Playgroud)
这是检查布尔值的更自然的表达式.
但是如果你需要使用is匹配器assertThat,你将需要这个导入:
import static org.hamcrest.CoreMatchers.*;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2281 次 |
| 最近记录: |