mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-09-19 15:11:42 +02:00
Separate and fix activity tests
This commit is contained in:
parent
36e73b2105
commit
a119afcbec
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2021 Allan Wang
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.pitchedapps.frost
|
||||
|
||||
import com.pitchedapps.frost.helper.TEST_FORMATTED_URL
|
||||
import com.pitchedapps.frost.helper.activityRule
|
||||
import com.pitchedapps.frost.utils.ARG_URL
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class StartActivityTest {
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val hildAndroidRule = HiltAndroidRule(this)
|
||||
|
||||
@get:Rule(order = 1)
|
||||
val activityRule = activityRule<StartActivity>(
|
||||
intentAction = {
|
||||
putExtra(ARG_URL, TEST_FORMATTED_URL)
|
||||
}
|
||||
)
|
||||
|
||||
@Test
|
||||
fun initializesSuccessfully() {
|
||||
activityRule.scenario.use {
|
||||
it.onActivity {
|
||||
// Verify no crash
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2021 Allan Wang
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.pitchedapps.frost.activities
|
||||
|
||||
import com.pitchedapps.frost.helper.activityRule
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class AboutActivityTest {
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val hildAndroidRule = HiltAndroidRule(this)
|
||||
|
||||
@get:Rule(order = 1)
|
||||
val activityRule = activityRule<AboutActivity>()
|
||||
|
||||
@Test
|
||||
fun initializesSuccessfully() {
|
||||
activityRule.scenario.use {
|
||||
it.onActivity {
|
||||
// Verify no crash
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021 Allan Wang
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.pitchedapps.frost.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import com.pitchedapps.frost.StartActivity
|
||||
import com.pitchedapps.frost.utils.ARG_IMAGE_URL
|
||||
import com.pitchedapps.frost.utils.ARG_URL
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Basic activity launching tests.
|
||||
*
|
||||
* Verifies that Hilt injections are not used prior to onCreate
|
||||
*/
|
||||
@HiltAndroidTest
|
||||
class ActivityConstructionTest {
|
||||
|
||||
@ApplicationContext
|
||||
@Inject
|
||||
lateinit var appContext: Context
|
||||
|
||||
@get:Rule
|
||||
val hiltRule = HiltAndroidRule(this)
|
||||
|
||||
@Before
|
||||
fun before() {
|
||||
hiltRule.inject()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aboutActivity() {
|
||||
launch<AboutActivity>()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun debugActivity() {
|
||||
launch<DebugActivity>()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun frostWebActivity() {
|
||||
launch<FrostWebActivity>(
|
||||
intentAction = {
|
||||
putExtra(ARG_URL, FORMATTED_URL)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun imageActivity() {
|
||||
launch<ImageActivity>(
|
||||
intentAction = {
|
||||
putExtra(ARG_IMAGE_URL, FORMATTED_URL)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Doesn't work, yet production is fine.")
|
||||
fun introActivity() {
|
||||
launch<IntroActivity>()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loginActivity() {
|
||||
launch<LoginActivity>()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun mainActivity() {
|
||||
launch<MainActivity>()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun selectorActivity() {
|
||||
launch<SelectorActivity>()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun settingsActivity() {
|
||||
launch<SettingsActivity>()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun startActivity() {
|
||||
launch<StartActivity>()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun tabCustomizerActivity() {
|
||||
launch<TabCustomizerActivity>()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun webOverlayMobileActivity() {
|
||||
launch<WebOverlayMobileActivity>(
|
||||
intentAction = {
|
||||
putExtra(ARG_URL, FORMATTED_URL)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun webOverlayDesktopActivity() {
|
||||
launch<WebOverlayDesktopActivity>(
|
||||
intentAction = {
|
||||
putExtra(ARG_URL, FORMATTED_URL)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun webOverlayActivity() {
|
||||
launch<WebOverlayActivity>(
|
||||
intentAction = {
|
||||
putExtra(ARG_URL, FORMATTED_URL)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private inline fun <reified A : Activity> launch(
|
||||
intentAction: Intent.() -> Unit = {},
|
||||
activityOptions: Bundle? = null
|
||||
): ActivityScenario<A> {
|
||||
val intent = Intent(appContext, A::class.java).also(intentAction)
|
||||
return ActivityScenario.launch(intent, activityOptions)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val FORMATTED_URL = "https://www.google.com"
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2021 Allan Wang
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.pitchedapps.frost.activities
|
||||
|
||||
import com.pitchedapps.frost.helper.activityRule
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class DebugActivityTest {
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val hildAndroidRule = HiltAndroidRule(this)
|
||||
|
||||
@get:Rule(order = 1)
|
||||
val activityRule = activityRule<DebugActivity>()
|
||||
|
||||
@Test
|
||||
fun initializesSuccessfully() {
|
||||
activityRule.scenario.use {
|
||||
it.onActivity {
|
||||
// Verify no crash
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2021 Allan Wang
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.pitchedapps.frost.activities
|
||||
|
||||
import com.pitchedapps.frost.helper.TEST_FORMATTED_URL
|
||||
import com.pitchedapps.frost.helper.activityRule
|
||||
import com.pitchedapps.frost.utils.ARG_URL
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class FrostWebActivityTest {
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val hildAndroidRule = HiltAndroidRule(this)
|
||||
|
||||
@get:Rule(order = 1)
|
||||
val activityRule = activityRule<FrostWebActivity>(
|
||||
intentAction = {
|
||||
putExtra(ARG_URL, TEST_FORMATTED_URL)
|
||||
}
|
||||
)
|
||||
|
||||
@Test
|
||||
fun initializesSuccessfully() {
|
||||
activityRule.scenario.use {
|
||||
it.onActivity {
|
||||
// Verify no crash
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -17,15 +17,18 @@
|
||||
package com.pitchedapps.frost.activities
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.rule.ActivityTestRule
|
||||
import ca.allanwang.kau.utils.isVisible
|
||||
import com.pitchedapps.frost.FrostTestRule
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.test.core.app.ActivityScenario
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.pitchedapps.frost.helper.TEST_FORMATTED_URL
|
||||
import com.pitchedapps.frost.helper.activityRule
|
||||
import com.pitchedapps.frost.helper.getResource
|
||||
import com.pitchedapps.frost.utils.ARG_COOKIE
|
||||
import com.pitchedapps.frost.utils.ARG_IMAGE_URL
|
||||
import com.pitchedapps.frost.utils.ARG_TEXT
|
||||
import com.pitchedapps.frost.utils.isIndirectImageUrl
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import okhttp3.internal.closeQuietly
|
||||
import okhttp3.mockwebserver.Dispatcher
|
||||
import okhttp3.mockwebserver.MockResponse
|
||||
@ -35,42 +38,31 @@ import okio.Buffer
|
||||
import okio.source
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
import org.junit.rules.TestRule
|
||||
import org.junit.rules.Timeout
|
||||
import org.junit.runner.RunWith
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@HiltAndroidTest
|
||||
class ImageActivityTest {
|
||||
|
||||
val activity: ActivityTestRule<ImageActivity> =
|
||||
ActivityTestRule(ImageActivity::class.java, true, false)
|
||||
@get:Rule(order = 0)
|
||||
val hildAndroidRule = HiltAndroidRule(this)
|
||||
|
||||
@get:Rule
|
||||
val rule: TestRule = RuleChain.outerRule(FrostTestRule()).around(activity)
|
||||
|
||||
@get:Rule
|
||||
val globalTimeout: Timeout = Timeout.seconds(15)
|
||||
|
||||
private fun launchActivity(imageUrl: String, text: String? = null, cookie: String? = null) {
|
||||
assertFalse(
|
||||
imageUrl.isIndirectImageUrl,
|
||||
"For simplicity, urls that are direct will be used without modifications in the production code."
|
||||
)
|
||||
val intent = Intent().apply {
|
||||
putExtra(ARG_IMAGE_URL, imageUrl)
|
||||
putExtra(ARG_TEXT, text)
|
||||
putExtra(ARG_COOKIE, cookie)
|
||||
@get:Rule(order = 1)
|
||||
val activityRule = activityRule<ImageActivity>(
|
||||
intentAction = {
|
||||
putExtra(ARG_IMAGE_URL, TEST_FORMATTED_URL)
|
||||
}
|
||||
activity.launchActivity(intent)
|
||||
}
|
||||
)
|
||||
|
||||
@get:Rule(order = 2)
|
||||
val globalTimeout: Timeout = Timeout.seconds(15)
|
||||
|
||||
lateinit var mockServer: MockWebServer
|
||||
|
||||
@ -84,6 +76,86 @@ class ImageActivityTest {
|
||||
mockServer.closeQuietly()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun initializesSuccessfully() = launchScenario(mockServer.url("image").toString()) {
|
||||
// Verify no crash
|
||||
}
|
||||
|
||||
@Test
|
||||
fun validImageTest() = launchScenario(mockServer.url("image").toString()) {
|
||||
mockServer.takeRequest()
|
||||
assertEquals(1, mockServer.requestCount, "One http request expected")
|
||||
// assertEquals(
|
||||
// FabStates.DOWNLOAD,
|
||||
// fabAction,
|
||||
// "Image should be successful, image should be downloaded"
|
||||
// )
|
||||
assertFalse(binding.error.isVisible, "Error should not be shown")
|
||||
val tempFile = assertNotNull(tempFile, "Temp file not created")
|
||||
assertTrue(tempFile.exists(), "Image should be located at temp file")
|
||||
assertTrue(
|
||||
System.currentTimeMillis() - tempFile.lastModified() < 2000L,
|
||||
"Image should have been modified within the last few seconds"
|
||||
)
|
||||
assertNull(errorRef, "No error should exist")
|
||||
tempFile.delete()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("apparently this fails")
|
||||
fun invalidImageTest() = launchScenario(mockServer.url("text").toString()) {
|
||||
mockServer.takeRequest()
|
||||
assertEquals(1, mockServer.requestCount, "One http request expected")
|
||||
assertTrue(binding.error.isVisible, "Error should be shown")
|
||||
|
||||
// assertEquals(
|
||||
// FabStates.ERROR,
|
||||
// fabAction,
|
||||
// "Text should not be a valid image format, error state expected"
|
||||
// )
|
||||
assertEquals(
|
||||
"Image format not supported",
|
||||
errorRef?.message,
|
||||
"Error message mismatch"
|
||||
)
|
||||
assertFalse(tempFile?.exists() == true, "Temp file should have been removed")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun errorTest() = launchScenario(mockServer.url("error").toString()) {
|
||||
mockServer.takeRequest()
|
||||
assertEquals(1, mockServer.requestCount, "One http request expected")
|
||||
assertTrue(binding.error.isVisible, "Error should be shown")
|
||||
// assertEquals(FabStates.ERROR, fabAction, "Error response code, error state expected")
|
||||
assertEquals(
|
||||
"Unsuccessful response for image: Error mock response",
|
||||
errorRef?.message,
|
||||
"Error message mismatch"
|
||||
)
|
||||
assertFalse(tempFile?.exists() == true, "Temp file should have been removed")
|
||||
}
|
||||
|
||||
private fun launchScenario(
|
||||
imageUrl: String,
|
||||
text: String? = null,
|
||||
cookie: String? = null,
|
||||
action: ImageActivity.() -> Unit
|
||||
) {
|
||||
assertFalse(
|
||||
imageUrl.isIndirectImageUrl,
|
||||
"For simplicity, urls that are direct will be used without modifications in the production code."
|
||||
)
|
||||
val intent =
|
||||
Intent(ApplicationProvider.getApplicationContext(), ImageActivity::class.java).apply {
|
||||
putExtra(ARG_IMAGE_URL, imageUrl)
|
||||
putExtra(ARG_TEXT, text)
|
||||
putExtra(ARG_COOKIE, cookie)
|
||||
}
|
||||
ActivityScenario.launch<ImageActivity>(intent).use {
|
||||
it.onActivity(action)
|
||||
}
|
||||
}
|
||||
|
||||
private fun mockServer(): MockWebServer {
|
||||
val img = Buffer()
|
||||
img.writeAll(getResource("bayer-pattern.jpg").source())
|
||||
@ -91,9 +163,10 @@ class ImageActivityTest {
|
||||
dispatcher = object : Dispatcher() {
|
||||
override fun dispatch(request: RecordedRequest): MockResponse =
|
||||
when {
|
||||
request.path?.contains("text") == true -> MockResponse().setResponseCode(200).setBody(
|
||||
"Valid mock text response"
|
||||
)
|
||||
request.path?.contains("text") == true -> MockResponse().setResponseCode(200)
|
||||
.setBody(
|
||||
"Valid mock text response"
|
||||
)
|
||||
request.path?.contains("image") == true -> MockResponse().setResponseCode(
|
||||
200
|
||||
).setBody(
|
||||
@ -105,62 +178,4 @@ class ImageActivityTest {
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun validImageTest() {
|
||||
launchActivity(mockServer.url("image").toString())
|
||||
mockServer.takeRequest()
|
||||
with(activity.activity) {
|
||||
assertEquals(1, mockServer.requestCount, "One http request expected")
|
||||
// assertEquals(
|
||||
// FabStates.DOWNLOAD,
|
||||
// fabAction,
|
||||
// "Image should be successful, image should be downloaded"
|
||||
// )
|
||||
assertFalse(binding.error.isVisible, "Error should not be shown")
|
||||
val tempFile = assertNotNull(tempFile, "Temp file not created")
|
||||
assertTrue(tempFile.exists(), "Image should be located at temp file")
|
||||
assertTrue(
|
||||
System.currentTimeMillis() - tempFile.lastModified() < 2000L,
|
||||
"Image should have been modified within the last few seconds"
|
||||
)
|
||||
assertNull(errorRef, "No error should exist")
|
||||
tempFile.delete()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun invalidImageTest() {
|
||||
launchActivity(mockServer.url("text").toString())
|
||||
mockServer.takeRequest()
|
||||
with(activity.activity) {
|
||||
assertEquals(1, mockServer.requestCount, "One http request expected")
|
||||
assertTrue(binding.error.isVisible, "Error should be shown")
|
||||
|
||||
// assertEquals(
|
||||
// FabStates.ERROR,
|
||||
// fabAction,
|
||||
// "Text should not be a valid image format, error state expected"
|
||||
// )
|
||||
assertEquals("Image format not supported", errorRef?.message, "Error message mismatch")
|
||||
assertFalse(tempFile?.exists() == true, "Temp file should have been removed")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun errorTest() {
|
||||
launchActivity(mockServer.url("error").toString())
|
||||
mockServer.takeRequest()
|
||||
with(activity.activity) {
|
||||
assertEquals(1, mockServer.requestCount, "One http request expected")
|
||||
assertTrue(binding.error.isVisible, "Error should be shown")
|
||||
// assertEquals(FabStates.ERROR, fabAction, "Error response code, error state expected")
|
||||
assertEquals(
|
||||
"Unsuccessful response for image: Error mock response",
|
||||
errorRef?.message,
|
||||
"Error message mismatch"
|
||||
)
|
||||
assertFalse(tempFile?.exists() == true, "Temp file should have been removed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2021 Allan Wang
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.pitchedapps.frost.activities
|
||||
|
||||
import com.pitchedapps.frost.helper.activityRule
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class IntroActivityTest {
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val hildAndroidRule = HiltAndroidRule(this)
|
||||
|
||||
@get:Rule(order = 1)
|
||||
val activityRule = activityRule<IntroActivity>()
|
||||
|
||||
@Test
|
||||
fun initializesSuccessfully() {
|
||||
activityRule.scenario.use {
|
||||
it.onActivity {
|
||||
// Verify no crash
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2021 Allan Wang
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.pitchedapps.frost.activities
|
||||
|
||||
import com.pitchedapps.frost.helper.activityRule
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class LoginActivityTest {
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val hildAndroidRule = HiltAndroidRule(this)
|
||||
|
||||
@get:Rule(order = 1)
|
||||
val activityRule = activityRule<LoginActivity>()
|
||||
|
||||
@Test
|
||||
fun initializesSuccessfully() {
|
||||
activityRule.scenario.use {
|
||||
it.onActivity {
|
||||
// Verify no crash
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2021 Allan Wang
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.pitchedapps.frost.activities
|
||||
|
||||
import com.pitchedapps.frost.helper.activityRule
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class MainActivityTest {
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val hildAndroidRule = HiltAndroidRule(this)
|
||||
|
||||
@get:Rule(order = 1)
|
||||
val activityRule = activityRule<MainActivity>()
|
||||
|
||||
@Test
|
||||
fun initializesSuccessfully() {
|
||||
activityRule.scenario.use {
|
||||
it.onActivity {
|
||||
// Verify no crash
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2021 Allan Wang
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.pitchedapps.frost.activities
|
||||
|
||||
import com.pitchedapps.frost.helper.activityRule
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class SelectorActivityTest {
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val hildAndroidRule = HiltAndroidRule(this)
|
||||
|
||||
@get:Rule(order = 1)
|
||||
val activityRule = activityRule<SelectorActivity>()
|
||||
|
||||
@Test
|
||||
fun initializesSuccessfully() {
|
||||
activityRule.scenario.use {
|
||||
it.onActivity {
|
||||
// Verify no crash
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2021 Allan Wang
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.pitchedapps.frost.activities
|
||||
|
||||
import com.pitchedapps.frost.helper.activityRule
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class SettingActivityTest {
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val hildAndroidRule = HiltAndroidRule(this)
|
||||
|
||||
@get:Rule(order = 1)
|
||||
val activityRule = activityRule<SettingsActivity>()
|
||||
|
||||
@Test
|
||||
fun initializesSuccessfully() {
|
||||
activityRule.scenario.use {
|
||||
it.onActivity {
|
||||
// Verify no crash
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2021 Allan Wang
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.pitchedapps.frost.activities
|
||||
|
||||
import com.pitchedapps.frost.helper.activityRule
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class TabCustomizerActivityTest {
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val hildAndroidRule = HiltAndroidRule(this)
|
||||
|
||||
@get:Rule(order = 1)
|
||||
val activityRule = activityRule<TabCustomizerActivity>()
|
||||
|
||||
@Test
|
||||
fun initializesSuccessfully() {
|
||||
activityRule.scenario.use {
|
||||
it.onActivity {
|
||||
// Verify no crash
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2021 Allan Wang
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.pitchedapps.frost.activities
|
||||
|
||||
import com.pitchedapps.frost.helper.activityRule
|
||||
import dagger.hilt.android.testing.HiltAndroidRule
|
||||
import dagger.hilt.android.testing.HiltAndroidTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
@HiltAndroidTest
|
||||
class WebOverlayActivityTest {
|
||||
|
||||
@get:Rule(order = 0)
|
||||
val hildAndroidRule = HiltAndroidRule(this)
|
||||
|
||||
@get:Rule(order = 1)
|
||||
val activityRule = activityRule<AboutActivity>()
|
||||
|
||||
@Test
|
||||
fun initializesSuccessfully() {
|
||||
activityRule.scenario.use {
|
||||
it.onActivity {
|
||||
// Verify no crash
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,12 @@
|
||||
*/
|
||||
package com.pitchedapps.frost.helper
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.rules.ActivityScenarioRule
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import java.io.InputStream
|
||||
|
||||
@ -30,3 +35,14 @@ private class Helper
|
||||
|
||||
fun getResource(resource: String): InputStream =
|
||||
Helper::class.java.classLoader!!.getResource(resource).openStream()
|
||||
|
||||
inline fun <reified A : Activity> activityRule(
|
||||
intentAction: Intent.() -> Unit = {},
|
||||
activityOptions: Bundle? = null
|
||||
): ActivityScenarioRule<A> {
|
||||
val intent =
|
||||
Intent(ApplicationProvider.getApplicationContext(), A::class.java).also(intentAction)
|
||||
return ActivityScenarioRule(intent, activityOptions)
|
||||
}
|
||||
|
||||
const val TEST_FORMATTED_URL = "https://www.google.com"
|
||||
|
Loading…
Reference in New Issue
Block a user