Added Tests for Profile Activity (#4062)

This commit is contained in:
Madhur Gupta 2020-12-06 00:19:25 +05:30 committed by GitHub
parent 4ac1b2d338
commit c1659f2bc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 92 additions and 2 deletions

View file

@ -81,15 +81,23 @@ dependencies {
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"
// Unit testing
testImplementation 'junit:junit:4.13'
testImplementation 'junit:junit:4.13.1'
testImplementation 'org.robolectric:robolectric:4.3'
testImplementation 'androidx.test:core:1.2.0'
testImplementation 'androidx.test:core:1.3.0'
testImplementation "com.squareup.okhttp3:mockwebserver:$OKHTTP_VERSION"
testImplementation "org.powermock:powermock-module-junit4:2.0.0-beta.5"
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"
testImplementation 'org.mockito:mockito-core:2.23.0'
testImplementation "com.jraska.livedata:testing-ktx:1.1.2"
testImplementation "androidx.arch.core:core-testing:2.1.0"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.1"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.3.1"
// Mockito and PowerMock
androidTestCompile ('org.powermock:powermock-mockito-release-full:1.6.0') {
exclude module: 'hamcrest-core'
exclude module: 'objenesis'
}
// Android testing
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"

View file

@ -0,0 +1,34 @@
package fr.free.nrw.commons.profile
import android.content.Context
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.powermock.api.mockito.PowerMockito
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest(
ProfileActivity::class
)
class ProfileActivityStartYourself {
@Mock
private lateinit var context: Context
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
}
@Test
@Throws(Exception::class)
fun testStartYourself() {
PowerMockito.mockStatic(ProfileActivity::class.java)
ProfileActivity.startYourself(context)
}
}

View file

@ -0,0 +1,48 @@
package fr.free.nrw.commons.profile
import android.content.Context
import fr.free.nrw.commons.TestCommonsApplication
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.powermock.api.mockito.PowerMockito.mockStatic
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [21], application = TestCommonsApplication::class)
class ProfileActivityTest {
private lateinit var activity: ProfileActivity
@Mock
private lateinit var context: Context
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
activity = Robolectric.buildActivity(ProfileActivity::class.java).create().get()
context = RuntimeEnvironment.application.applicationContext
}
@Test
@Throws(Exception::class)
fun checkActivityNotNull() {
Assert.assertNotNull(activity)
}
@Test
@Throws(Exception::class)
fun testOnDestroy() {
activity.onDestroy()
}
}