This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExampleUnitTest{ | |
@Test | |
fun addition_isCorrect(){ | |
assertEquals(expected:4,actual:2+2) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4::class) | |
class ExampleInstrumentedTest{ | |
@Test | |
fun useAppContext(){ | |
//Context of the app under test. | |
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | |
assertEquals("com.cheezycode.unittestingexample", appContext.packageName) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Helper { | |
fun isPallindrome(input: String): Boolean{ | |
var i = 0 | |
var j = input.length - 1 | |
var result = true | |
while (i < j){ | |
if(input[i] != input[j]){ | |
result = false | |
break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(value = Parameterized::class) | |
class ParameterizedExample(val input:String,val expectedValue:Boolean){ | |
@Test | |
fun test(){ | |
val helper = Helper() | |
val result = helper.isPallindrome(input) | |
assertEquals(expectedValue,result) | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Quote(val text:String,val author:String) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import androidx.test.core.app.ApplicationProvider | |
import com.google.gson.JsonSyntaxException | |
import org.junit.Assert.* | |
import org.junit.After | |
import org.junit.Before | |
import org.junit.Test | |
import java.io.FileNotFoundException |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PasswordTest{ | |
@Test | |
fun `validatePassword blank input expected required field`(){ | |
val sut = Utils() | |
val result = sut.validatePassword(" ") | |
assertEquals("Password is required field", result) | |
} | |
@Test | |
fun `validatePassword 2CharInput expected validation Msg`(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.lifecycle.LiveData | |
import androidx.lifecycle.Observer | |
import java.util.concurrent.CountDownLatch | |
import java.util.concurrent.TimeUnit | |
import java.util.concurrent.TimeoutException | |
fun <T> LiveData<T>.getOrAwaitValue( | |
time: Long = 2, | |
timeUnit: TimeUnit = TimeUnit.SECONDS, | |
afterObserve: () -> Unit = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class User( | |
val id:Int, | |
val name:String, | |
val email:String, | |
val password:String | |
) | |
enum class LOGIN_STATUS{ | |
INVALID_USER, | |
INVALID_PASSWORD, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QuoteManagerTest{ | |
@Mock | |
lateinit var context: Context | |
@Mock | |
lateinit var assertManager: AssertManager | |
@Before | |
fun setup(){ |
OlderNewer