mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Added Unit Tests for WelcomeActivity Class (#3933)
This commit is contained in:
parent
93225149d8
commit
66469e006a
1 changed files with 83 additions and 0 deletions
|
|
@ -0,0 +1,83 @@
|
||||||
|
package fr.free.nrw.commons
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.widget.TextView
|
||||||
|
import fr.free.nrw.commons.quiz.QuizActivity
|
||||||
|
import junit.framework.Assert.assertEquals
|
||||||
|
import junit.framework.Assert.assertNotNull
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.robolectric.Robolectric
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
import org.robolectric.Shadows.shadowOf
|
||||||
|
import org.robolectric.annotation.Config
|
||||||
|
import org.robolectric.shadows.ShadowActivity
|
||||||
|
import org.robolectric.shadows.ShadowIntent
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests Welcome Activity Methods
|
||||||
|
*/
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||||
|
class WelcomeActivityUnitTest {
|
||||||
|
|
||||||
|
private lateinit var activity: WelcomeActivity
|
||||||
|
private lateinit var finishTutorialButton: TextView
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the Class and Views for Test
|
||||||
|
* Initialise the activity with isQuiz as true for Intent Extra
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
val intent = Intent().putExtra("isQuiz", true)
|
||||||
|
activity = Robolectric.buildActivity(WelcomeActivity::class.java, intent)
|
||||||
|
.get()
|
||||||
|
activity.onCreate(null)
|
||||||
|
finishTutorialButton = activity.findViewById(R.id.finishTutorialButton)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the activity is not null and member variables are not null
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun checkActivityNotNull() {
|
||||||
|
assertNotNull(activity)
|
||||||
|
assertNotNull(activity.pager)
|
||||||
|
assertNotNull(activity.indicator)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the activity onDestroy method launches correct intent when isQuiz is true
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testOnDestroy() {
|
||||||
|
activity.onDestroy()
|
||||||
|
val shadowActivity: ShadowActivity = shadowOf(activity)
|
||||||
|
val startedIntent = shadowActivity.nextStartedActivity
|
||||||
|
val shadowIntent: ShadowIntent = shadowOf(startedIntent)
|
||||||
|
assertEquals(shadowIntent.intentClass, QuizActivity::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the finish Tutorial Button executes the finishTutorial method without any errors
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testFinishTutorial() {
|
||||||
|
finishTutorialButton.performClick()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the onBackPressed method executes without any errors
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testOnBackPressed() {
|
||||||
|
activity.onBackPressed()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue