Skip to content

Commit

Permalink
Merge pull request #7 from liip/test
Browse files Browse the repository at this point in the history
Update test runner
  • Loading branch information
jschmid authored Nov 20, 2019
2 parents 9babba8 + a265139 commit 4691fea
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
5 changes: 0 additions & 5 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ android {
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
Expand All @@ -31,10 +30,6 @@ dependencies {
// Android
implementation 'com.android.support.constraint:constraint-layout:1.1.3'

// Tests
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'

// Library
implementation project(':library')

Expand Down
5 changes: 2 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ android {
versionCode 1
versionName "1.0.3"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -35,7 +34,7 @@ dependencies {

// Test
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
}
repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package ch.liip.sweetpreferences

import android.content.Context
import android.preference.PreferenceManager
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith


@RunWith(AndroidJUnit4::class)
class SweetPreferencesBuilderTest {

@Test(expected = IllegalStateException::class)
Expand All @@ -24,7 +21,7 @@ class SweetPreferencesBuilderTest {
@Test
fun takesTheGivenPreference() {

val context = InstrumentationRegistry.getTargetContext()
val context = InstrumentationRegistry.getInstrumentation().context
val systemPrefs = context.getSharedPreferences("test", Context.MODE_PRIVATE)
systemPrefs.edit().clear().commit()

Expand All @@ -39,7 +36,7 @@ class SweetPreferencesBuilderTest {
@Test
fun takesTheDefaultPreference() {

val context = InstrumentationRegistry.getTargetContext()
val context = InstrumentationRegistry.getInstrumentation().context
val defaultPrefs = PreferenceManager.getDefaultSharedPreferences(context)
defaultPrefs.edit().clear().commit()
val testPrefs = context.getSharedPreferences("test", Context.MODE_PRIVATE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package ch.liip.sweetpreferences

import android.content.Context
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class SweetPreferencesTest {

private lateinit var prefs: SweetPreferences
Expand All @@ -17,7 +14,7 @@ class SweetPreferencesTest {
@Before
fun setup() {

val context = InstrumentationRegistry.getTargetContext()
val context = InstrumentationRegistry.getInstrumentation().context
val systemPrefs = context.getSharedPreferences("test", Context.MODE_PRIVATE)
systemPrefs.edit().clear().commit()

Expand Down

0 comments on commit 4691fea

Please sign in to comment.