-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for running tests #65
Changes from 14 commits
5dac064
d768555
53e25f3
9af54a0
7bc9afe
af0a887
3d1d919
058b647
8a1fe81
f31af77
87060f7
111a0e3
0cc155c
240660d
8dff09c
59f419e
b566448
2ad6549
b74d251
0fb0a27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ import androidx.test.espresso.intent.Intents.times | |
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.filters.SmallTest | ||
import androidx.work.Configuration | ||
import androidx.work.WorkManager | ||
import com.infinum.sentinel.ui.SentinelTestApplication | ||
import com.infinum.sentinel.ui.main.SentinelActivity | ||
import com.infinum.sentinel.ui.tools.DummyTool | ||
|
@@ -32,6 +34,10 @@ internal class SentinelTests { | |
@JvmStatic | ||
fun setupBeforeClass() { | ||
context = ApplicationProvider.getApplicationContext<SentinelTestApplication>() | ||
WorkManager.initialize( | ||
context, | ||
Configuration.Builder().build() | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only for Tests. WorkManager is missing and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By removing meta-data for WorkManager this can also be removed. |
||
} | ||
} | ||
|
||
|
@@ -79,17 +85,16 @@ internal class SentinelTests { | |
fun sentinel_show() { | ||
Sentinel.show() | ||
|
||
intended(hasComponent(ComponentName(context, SentinelActivity::class.java)), times(2)) | ||
intended(hasComponent(ComponentName(context, SentinelActivity::class.java)), times(1)) | ||
} | ||
|
||
// @Test | ||
// @SmallTest | ||
// @RequiresDevice | ||
// fun sentinel_showDevice() { | ||
// val instance = Sentinel.watch(context) | ||
// | ||
// instance.show() | ||
// | ||
// intended(hasComponent(ComponentName(context, SentinelActivity::class.java)), times(1)) | ||
// } | ||
@Test | ||
@SmallTest | ||
fun sentinel_showDevice() { | ||
val instance = Sentinel.watch() | ||
|
||
instance.show() | ||
|
||
intended(hasComponent(ComponentName(context, SentinelActivity::class.java)), times(1)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,24 @@ import com.infinum.sentinel.ui.SentinelTestApplication | |
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertTrue | ||
import org.junit.BeforeClass | ||
import org.junit.Ignore | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@Ignore("This test is ignored because it's failing on CI") | ||
@RunWith(AndroidJUnit4::class) | ||
internal class PermissionsCollectorTests { | ||
|
||
companion object { | ||
|
||
private val APPENDED_PERMISSIONS = mapOf(Manifest.permission.REORDER_TASKS to true) | ||
private val APPENDED_PERMISSIONS = mapOf( | ||
Manifest.permission.REORDER_TASKS to true, | ||
Manifest.permission.POST_NOTIFICATIONS to false, | ||
Manifest.permission.POST_NOTIFICATIONS to false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. POST_NOTIFICATIONS twice There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still twice... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed, finally π |
||
Manifest.permission.WAKE_LOCK to true, | ||
Manifest.permission.ACCESS_NETWORK_STATE to true, | ||
Manifest.permission.RECEIVE_BOOT_COMPLETED to true, | ||
Manifest.permission.FOREGROUND_SERVICE to true, | ||
"com.infinum.sentinel.test.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION" to true | ||
) | ||
|
||
lateinit var actualPermissions: Map<String, Boolean> | ||
|
||
|
@@ -40,13 +47,15 @@ internal class PermissionsCollectorTests { | |
fun permissions_notDeclared() { | ||
assertTrue(actualPermissions.isNotEmpty()) | ||
assertEquals(APPENDED_PERMISSIONS.size, actualPermissions.size) | ||
assertEquals( | ||
APPENDED_PERMISSIONS.containsKey(Manifest.permission.REORDER_TASKS), | ||
actualPermissions.containsKey(Manifest.permission.REORDER_TASKS) | ||
) | ||
assertEquals( | ||
APPENDED_PERMISSIONS[Manifest.permission.REORDER_TASKS], | ||
actualPermissions[Manifest.permission.REORDER_TASKS] | ||
) | ||
APPENDED_PERMISSIONS.forEach { (permission, expectedStatus) -> | ||
assertEquals( | ||
APPENDED_PERMISSIONS.containsKey(permission), | ||
actualPermissions.containsKey(permission) | ||
) | ||
assertEquals( | ||
expectedStatus, | ||
actualPermissions[permission] | ||
) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,10 @@ import org.junit.Assert.assertNotNull | |
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.BeforeClass | ||
import org.junit.Ignore | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.util.ReflectionHelpers | ||
|
||
@Ignore("This test is ignored because it's failing on CI") | ||
@RunWith(AndroidJUnit4::class) | ||
internal class HtmlStringBuilderTests { | ||
|
||
|
@@ -123,6 +121,33 @@ internal class HtmlStringBuilderTests { | |
?.use { it.readText() } | ||
.orEmpty() | ||
|
||
private fun checkDeviceSpecificFields(html: String): String { | ||
val fields = listOf( | ||
"screen_width", | ||
"screen_height", | ||
"screen_size", | ||
"screen_density", | ||
"font_scale" | ||
) | ||
|
||
val fieldPatterns = fields.map { field -> | ||
field to Regex("""<div>$field:\s*[^<]*</div>""") | ||
} | ||
|
||
var updatedHtml = html | ||
|
||
fieldPatterns.forEach { (field, pattern) -> | ||
val matchResult = pattern.find(updatedHtml) | ||
if (matchResult == null) { | ||
throw AssertionError("Field $field is missing in the device object") | ||
} else { | ||
updatedHtml = updatedHtml.replace(matchResult.value, """<div>$field: </div>""") | ||
} | ||
} | ||
|
||
return updatedHtml | ||
} | ||
|
||
Comment on lines
+124
to
+150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When it comes to When I get more familiar with Roboelectric, I will return to this, unless you have suggestions. |
||
@Before | ||
fun preferences_deleteDir() { | ||
val prefsDirectory = | ||
|
@@ -144,7 +169,8 @@ internal class HtmlStringBuilderTests { | |
|
||
assertNotNull(actualData) | ||
assertTrue(actualData.isNotBlank()) | ||
assertEquals(EXPECTED_DATA_NO_PREFERENCES, actualData) | ||
val cleanedUpData = checkDeviceSpecificFields(actualData) | ||
assertEquals(EXPECTED_DATA_NO_PREFERENCES, cleanedUpData) | ||
} | ||
|
||
@Test | ||
|
@@ -167,6 +193,7 @@ internal class HtmlStringBuilderTests { | |
|
||
assertNotNull(actualData) | ||
assertTrue(actualData.isNotBlank()) | ||
assertEquals(EXPECTED_DATA, actualData) | ||
val cleanedUpData = checkDeviceSpecificFields(actualData) | ||
assertEquals(EXPECTED_DATA, cleanedUpData) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
We removed need for this in last release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember if there were any conflicts, but it is possible it is from that. I will re-check this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I see now. This is from initial commit to this branch by Neven when we were figuring out what is wrong with the tests. I will check if this can be removed.