Automatically skipping real device tests if no connection to adb server.

This commit is contained in:
Samuel Carlsson 2016-03-28 16:06:44 +02:00
parent 4b3708d59c
commit 09a989e144

View File

@ -1,5 +1,6 @@
package se.vidstige.jadb.test;
import org.junit.Before;
import org.junit.Test;
import se.vidstige.jadb.JadbConnection;
import se.vidstige.jadb.JadbDevice;
@ -8,27 +9,36 @@ import se.vidstige.jadb.RemoteFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
public class RealDeviceTestCases {
private JadbConnection jadb;
@Before
public void connect() throws IOException {
try {
jadb = new JadbConnection();
jadb.getHostVersion();
} catch (Exception e) {
org.junit.Assume.assumeNoException(e);
}
}
@Test
public void testGetHostVersion() throws Exception {
JadbConnection jadb = new JadbConnection();
jadb.getHostVersion();
}
@Test
public void testGetDevices() throws Exception {
//JadbConnection jadb = new JadbConnection("localhost", 15037);
JadbConnection jadb = new JadbConnection();
List<JadbDevice> actual = jadb.getDevices();
//Assert.assertEquals("emulator-5554", actual.get(0).getSerial());
}
@Test
public void testListFilesTwice() throws Exception {
JadbConnection jadb = new JadbConnection();
JadbDevice any = jadb.getAnyDevice();
for (RemoteFile f : any.list("/")) {
System.out.println(f.getPath());
@ -41,7 +51,6 @@ public class RealDeviceTestCases {
@Test
public void testPushFile() throws Exception {
JadbConnection jadb = new JadbConnection();
JadbDevice any = jadb.getAnyDevice();
any.push(new File("README.md"), new RemoteFile("/sdcard/README.md"));
//second read on the same device
@ -50,14 +59,12 @@ public class RealDeviceTestCases {
@Test(expected = JadbException.class)
public void testPushFileToInvalidPath() throws Exception {
JadbConnection jadb = new JadbConnection();
JadbDevice any = jadb.getAnyDevice();
any.push(new File("README.md"), new RemoteFile("/no/such/directory/README.md"));
}
@Test
public void testPullFile() throws Exception {
JadbConnection jadb = new JadbConnection();
JadbDevice any = jadb.getAnyDevice();
any.pull(new RemoteFile("/sdcard/README.md"), new File("foobar.md"));
//second read on the same device
@ -66,14 +73,12 @@ public class RealDeviceTestCases {
@Test(expected = JadbException.class)
public void testPullInvalidFile() throws Exception {
JadbConnection jadb = new JadbConnection();
JadbDevice any = jadb.getAnyDevice();
any.pull(new RemoteFile("/file/does/not/exist"), new File("xyz"));
}
@Test
public void testShellExecuteTwice() throws Exception {
JadbConnection jadb = new JadbConnection();
JadbDevice any = jadb.getAnyDevice();
any.executeShell(System.out, "ls /");
any.executeShell(System.out, "ls", "-la", "/");
@ -81,7 +86,6 @@ public class RealDeviceTestCases {
@Test
public void testScreenshot() throws Exception {
JadbConnection jadb = new JadbConnection();
JadbDevice any = jadb.getAnyDevice();
FileOutputStream outputStream = new FileOutputStream(new File("screenshot.png"));
any.executeShell(outputStream, "screencap", "-p");