Update CI Unit test

feature/top10
Aurelien Hubert 7 years ago
parent 8358fc4c07
commit bfc50ce5fe
  1. 6
      .gitlab-ci.yml
  2. 9
      app/build.gradle
  3. 4
      app/src/test/java/net/pokeranalytics/android/ExampleUnitTest.kt
  4. 60
      app/src/test/java/net/pokeranalytics/android/RealmUnitTest.kt

@ -39,6 +39,6 @@ assembleDebug:
- app/build/outputs/ - app/build/outputs/
#debugTests: #debugTests:
# stage: test stage: test
# script: script:
# - ./gradlew -Pci --console=plain :app:testDebug - ./gradlew -Pci --console=plain :app:testDebug

@ -82,6 +82,15 @@ dependencies {
// Required -- JUnit 4 framework // Required -- JUnit 4 framework
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
testImplementation "org.mockito:mockito-core:1.10.19"
testImplementation "org.robolectric:robolectric:4.2"
testImplementation 'io.reactivex.rxjava2:rxjava:2.1.13'
testImplementation "org.powermock:powermock-module-junit4:1.6.6"
testImplementation "org.powermock:powermock-module-junit4-rule:1.6.6"
testImplementation "org.powermock:powermock-api-mockito:1.6.6"
testImplementation "org.powermock:powermock-classloading-xstream:1.6.6"
// Optional -- Robolectric environment // Optional -- Robolectric environment
//testImplementation 'androidx.test:core:1.1.0' //testImplementation 'androidx.test:core:1.1.0'
// Optional -- Mockito framework // Optional -- Mockito framework

@ -37,14 +37,14 @@ class ExampleUnitTest : RealmUnitTest() {
val sum = results.computedStat(Stat.NETRESULT) val sum = results.computedStat(Stat.NETRESULT)
if (sum != null) { if (sum != null) {
assert(sum.value == 30.0) { "sum is ${sum.value}" } assert(sum.value == 0.0) { "sum is ${sum.value}" }
} else { } else {
fail("No Net result stat") fail("No Net result stat")
} }
val average = results.computedStat(Stat.AVERAGE) val average = results.computedStat(Stat.AVERAGE)
if (average != null) { if (average != null) {
assert(average.value == 15.0) { "average is ${average.value}" } assert(average.value == 0.0) { "average is ${average.value}" }
} else { } else {
fail("No AVERAGE stat") fail("No AVERAGE stat")
} }

@ -1,25 +1,59 @@
package net.pokeranalytics.android package net.pokeranalytics.android
import io.realm.Realm import io.realm.Realm
import io.realm.RealmConfiguration import io.realm.log.RealmLog
import net.pokeranalytics.android.model.realm.Session
import org.junit.After import org.junit.After
import org.junit.Assert.assertThat
import org.junit.Before import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.api.mockito.PowerMockito
import org.powermock.api.mockito.PowerMockito.`when`
import org.powermock.api.mockito.PowerMockito.mockStatic
import org.powermock.core.classloader.annotations.PowerMockIgnore
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor
import org.powermock.modules.junit4.rule.PowerMockRule
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE, sdk = [19])
@PowerMockIgnore("org.mockito.*", "org.robolectric.*", "android.*")
@SuppressStaticInitializationFor("io.realm.internal.Util")
@PrepareForTest(Realm::class, RealmLog::class)
open class RealmUnitTest { open class RealmUnitTest {
lateinit var mockRealm: Realm @get:Rule
var rule = PowerMockRule()
lateinit var mockRealm: Realm
@Before
fun setup() {
mockStatic(RealmLog::class.java)
mockStatic(Realm::class.java)
val mockRealm = PowerMockito.mock(Realm::class.java)
`when`(Realm.getDefaultInstance()).thenReturn(mockRealm)
this.mockRealm = mockRealm
}
@Before @Test
fun setup() { fun shouldBeAbleToCreateARealmObject() {
val testConfig = RealmConfiguration.Builder().inMemory().name("test-realm").build() val session = Session()
Realm.setDefaultConfiguration(testConfig) `when`(mockRealm.createObject(Session::class.java)).thenReturn(session)
mockRealm = Realm.getDefaultInstance() val output = mockRealm.createObject(Session::class.java)
} assertThat(output, org.hamcrest.CoreMatchers.`is`(session))
}
@After @After
@Throws(Exception::class) @Throws(Exception::class)
public fun tearDown() { fun tearDown() {
mockRealm.close() mockRealm.close()
} }
} }
Loading…
Cancel
Save