java: refactoring of Instrumented Tests

This commit is contained in:
Unknown 2020-07-13 14:58:47 +02:00
parent 12e560e50e
commit 9a76611330
2 changed files with 43 additions and 8 deletions

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.etlegacy.app"
android:versionCode="1"
android:versionName="1.0">
<instrumentation android:targetPackage="org.etlegacy.app"
android:name="android.support.test.runner.AndroidJUnitRunner"/>
</manifest>

View file

@ -1,13 +1,18 @@
package org.etlegacy.app;
import android.content.Context;
import android.app.Application;
import android.app.Instrumentation;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.util.DisplayMetrics;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.robotium.solo.Solo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.os.SystemClock.sleep;
import static org.junit.Assert.assertEquals;
/**
@ -19,19 +24,37 @@ import static org.junit.Assert.assertEquals;
public class TestETL {
private Solo solo;
Instrumentation instrumentation;
InstrumentationRegistry instrumentationRegistry;
Application app;
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
@Before
public void setUp() throws Exception {
app = (Application) instrumentationRegistry.getTargetContext().getApplicationContext();
assertEquals("org.etlegacy.app", appContext.getPackageName());
instrumentation = new Instrumentation();
instrumentation = instrumentationRegistry.getInstrumentation();
instrumentation.runOnMainSync(new Runnable() {
@Override
public void run() {
instrumentation.callApplicationOnCreate(app);
}
});
}
@Test
public void clickOnNickEntry() throws Exception {
// Perform click on Nickname Entry
// TODO: Implement
assertEquals("org.etlegacy.app", app.getPackageName());
DisplayMetrics displaymetrics = new DisplayMetrics();
if (app.getApplicationContext().getClass().getSimpleName() == "ETLActivity") {
sleep(10000);
solo.drag(0, displaymetrics.widthPixels, 0, displaymetrics.heightPixels / 2, 100);
}
}
}