'changing test cases from junit to mockito in android app
i am trying to test out an email field in login screen. i want to change the following code using mockito. can it be done. pls help??
class EmailValidatorTest {
@Test
fun emailValidator_CorrectEmailSimple_ReturnsGood() {
val email = "[email protected]"
assertThat(EmailPasswordChecker.getEmailState(email)).isEqualTo(EmailState.GOOD)
}
@Test
fun emailValidator_CorrectEmailSubDomain_ReturnsGood() {
val email = "[email protected]"
assertThat(EmailPasswordChecker.getEmailState(email)).isEqualTo(EmailState.GOOD)
}
@Test
fun emailValidator_InvalidEmailNoTld_ReturnsIncorrect() {
val email = "name@email"
assertThat(EmailPasswordChecker.getEmailState(email)).isEqualTo(EmailState.INCORRECT)
}
@Test
fun emailValidator_InvalidEmailDoubleDot_ReturnsIncorrect() {
val email = "[email protected]"
assertThat(EmailPasswordChecker.getEmailState(email)).isEqualTo(EmailState.INCORRECT)
}
@Test
fun emailValidator_InvalidEmailNoUsername_ReturnsIncorrect() {
val email = "@email.com"
assertThat(EmailPasswordChecker.getEmailState(email)).isEqualTo(EmailState.INCORRECT)
}
@Test
fun emailValidator_EmptyString_ReturnsEmpty() {
val email = ""
assertThat(EmailPasswordChecker.getEmailState(email)).isEqualTo(EmailState.EMPTY)
}
here is some more helper code->
object EmailPasswordChecker{
//some code that i cant share
}
enum class EmailState {
GOOD,
INCORRECT,
EMPTY
}
these are simple tests that i wrote using JUnit. but now i need to change them using mockito. can someone help me with the code? i am fairly new to testing so i am not exactly able to figure out how this framework is working.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
