Merge pull request #1 from equalitie/instrumented-tests

Instrumented tests
This commit is contained in:
Miguel 2022-10-12 11:23:31 -05:00 committed by GitHub
commit 0a009f7f4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 25 deletions

View File

@ -44,7 +44,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'ie.equalit.ouinet:ouinet-arm64-v8a:0.20.0'
implementation 'ie.equalit.ouinet:ouinet-arm64-v8a:0.21.2'
implementation 'com.getkeepsafe.relinker:relinker:1.4.4'
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
testImplementation 'junit:junit:4.+'

View File

@ -1,24 +0,0 @@
package ie.equalit.ouinet_examples.android_kotlin
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("ie.equalit.ouinet_examples.android_kotlin", appContext.packageName)
}
}

View File

@ -0,0 +1,59 @@
package ie.equalit.ouinet_examples.android_kotlin
import ie.equalit.ouinet.Config
import ie.equalit.ouinet.Ouinet
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class OuinetInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("ie.equalit.ouinet_examples.android_kotlin", appContext.packageName)
}
@Test
fun testStartStop() {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
var config = Config.ConfigBuilder(appContext)
.setCacheType("bep5-http")
.setCacheHttpPubKey(BuildConfig.CACHE_PUB_KEY)
.build()
var ouinet = Ouinet(appContext, config)
for (i in 1..5) {
ouinet.start()
Thread.sleep(1000);
assertTrue(ouinet.state.toString().startsWith("Start"))
ouinet.stop()
assertEquals("Stopped", ouinet.state.toString());
}
for (i in 1..3) {
Thread.sleep(100);
ouinet.stop()
assertEquals("Stopped", ouinet.state.toString());
}
ouinet.start()
Thread.sleep(1000);
assertTrue(ouinet.state.toString().startsWith("Start"))
ouinet.stop()
assertEquals("Stopped", ouinet.state.toString());
}
}