Skip to content

Commit

Permalink
SCRUM-102 Test CU13
Browse files Browse the repository at this point in the history
  • Loading branch information
COLOSO70 committed Dec 14, 2023
1 parent 20e0205 commit 5e67207
Show file tree
Hide file tree
Showing 3 changed files with 253 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dependencies {
androidTestImplementation("androidx.navigation:navigation-testing:$nav_version")

// Jetpack Compose Integration
implementation("androidx.navigation:navigation-compose:$nav_version")
//implementation("androidx.navigation:navigation-compose:$nav_version")

implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.1")
Expand All @@ -96,4 +96,18 @@ dependencies {
implementation("org.apache.poi:poi:5.1.0")
implementation("org.apache.poi:poi-ooxml:5.1.0")

testImplementation("junit:junit:4.13.2")
testImplementation("org.mockito:mockito-core:4.6.1")
testImplementation("org.mockito:mockito-junit-jupiter:4.6.1")
testImplementation("com.squareup.okhttp3:mockwebserver:4.9.1")
androidTestImplementation("androidx.test.ext:junit:1.1.5")

// Espresso dependencies
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation("androidx.test:runner:1.5.1")
androidTestImplementation("androidx.test:rules:1.5.0")

//import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
androidTestImplementation("androidx.test.espresso:espresso-contrib:3.5.1")

}
141 changes: 141 additions & 0 deletions app/src/androidTest/java/es/unex/giis/asee/gepeto/view/TestCU13.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package es.unex.giis.asee.gepeto.view


import android.view.View
import android.view.ViewGroup
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.*
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import es.unex.giis.asee.gepeto.R
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.`is`
import org.hamcrest.TypeSafeMatcher
import org.hamcrest.core.IsInstanceOf
import org.junit.After
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class TestCU13 {

@Rule
@JvmField
var mActivityScenarioRule = ActivityScenarioRule(LoginActivity::class.java)

@Test
fun registerActivityTest() {
val materialButton = onView(
allOf(
withId(R.id.bt_register), withText("Registrarse"),
childAtPosition(
childAtPosition(
withClassName(`is`("android.widget.LinearLayout")),
4
),
1
)
)
)
materialButton.perform(scrollTo(), click())

val appCompatEditText = onView(
allOf(
withId(R.id.et_username),
childAtPosition(
childAtPosition(
withClassName(`is`("androidx.constraintlayout.widget.ConstraintLayout")),
3
),
1
)
)
)
appCompatEditText.perform(scrollTo(), replaceText("Espresso"), closeSoftKeyboard())

val appCompatEditText2 = onView(
allOf(
withId(R.id.et_password),
childAtPosition(
childAtPosition(
withClassName(`is`("androidx.constraintlayout.widget.ConstraintLayout")),
3
),
3
)
)
)
appCompatEditText2.perform(scrollTo(), replaceText("Conazucar"), closeSoftKeyboard())

val appCompatEditText3 = onView(
allOf(
withId(R.id.et_repassword),
childAtPosition(
childAtPosition(
withClassName(`is`("androidx.constraintlayout.widget.ConstraintLayout")),
3
),
5
)
)
)
appCompatEditText3.perform(scrollTo(), replaceText("Conazucar"), closeSoftKeyboard())

val materialButton2 = onView(
allOf(
withId(R.id.bt_register), withText("Registrarse"),
childAtPosition(
childAtPosition(
withClassName(`is`("android.widget.LinearLayout")),
6
),
0
)
)
)
materialButton2.perform(scrollTo(), click())

val editText = onView(
allOf(
withId(R.id.et_username), withText("Espresso"),
withParent(withParent(IsInstanceOf.instanceOf(android.view.ViewGroup::class.java))),
isDisplayed()
)
)
editText.check(matches(withText("Espresso")))

val editText2 = onView(
allOf(
withId(R.id.et_password), withText("Conazucar"),
withParent(withParent(IsInstanceOf.instanceOf(android.view.ViewGroup::class.java))),
isDisplayed()
)
)
editText2.check(matches(withText("Conazucar")))
}

private fun childAtPosition(
parentMatcher: Matcher<View>, position: Int
): Matcher<View> {

return object : TypeSafeMatcher<View>() {
override fun describeTo(description: Description) {
description.appendText("Child at position $position in parent ")
parentMatcher.describeTo(description)
}

public override fun matchesSafely(view: View): Boolean {
val parent = view.parent
return parent is ViewGroup && parentMatcher.matches(parent)
&& view == parent.getChildAt(position)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package es.unex.giis.asee.gepeto.utils

import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.mockito.MockitoAnnotations

class CredentialCheckTest {

@Before
fun setup() {
}

@Test
fun login() {

//Username vacío
assertEquals("Invalid username", CredentialCheck.login("", "password123").msg)
assertTrue(CredentialCheck.login("", "password123").fail)
//Username corto
assertEquals("Invalid username", CredentialCheck.login("abc", "password123").msg)
assertTrue(CredentialCheck.login("abc", "password123").fail)
//Password vacío
assertEquals("Invalid password", CredentialCheck.login("username", "").msg)
assertTrue(CredentialCheck.login("username", "").fail)
//Password corto
assertEquals("Invalid password", CredentialCheck.login("username", "abc").msg)
assertTrue(CredentialCheck.login("username", "abc").fail)
//Credenciales válidas
assertEquals("Your credentials are OK", CredentialCheck.login("username", "password123").msg)
assertFalse(CredentialCheck.login("username", "password123").fail)
}


@Test
fun testPasswordOk() {
// Password vacío
assertEquals("Invalid password", CredentialCheck.passwordOk("", "password123").msg)
assertTrue(CredentialCheck.passwordOk("", "password123").fail)

// Password corto
assertEquals("Invalid password", CredentialCheck.passwordOk("abc", "abc").msg)
assertTrue(CredentialCheck.passwordOk("pass", "password123").fail)

// Contraseñas no coinciden
assertEquals("Passwords do not match", CredentialCheck.passwordOk("password123", "password456").msg)
assertTrue(CredentialCheck.passwordOk("password123", "password456").fail)

// Contraseñas válidas
assertEquals("Your credentials are OK", CredentialCheck.passwordOk("password123", "password123").msg)
assertFalse(CredentialCheck.passwordOk("password123", "password123").fail)
}

@Test
fun testNewPasswordOk() {
// Password vacío
assertEquals("Invalid password", CredentialCheck.newPasswordOk("").msg)
assertTrue(CredentialCheck.newPasswordOk("").fail)

// Password corto
assertEquals("Invalid password", CredentialCheck.newPasswordOk("abc").msg)
assertTrue(CredentialCheck.newPasswordOk("abc").fail)

// Contraseña válida
assertEquals("Your credentials are OK", CredentialCheck.newPasswordOk("password123").msg)
assertFalse(CredentialCheck.newPasswordOk("password123").fail)
}

@Test
fun testJoin() {
// Username vacío
assertEquals("Invalid username", CredentialCheck.join("", "password123", "password123").msg)
assertTrue(CredentialCheck.join("", "password123", "password123").fail)

// Username corto
assertEquals("Invalid username", CredentialCheck.join("abc", "password123", "password123").msg)
assertTrue(CredentialCheck.join("abc", "password123", "password123").fail)

// Password vacío
assertEquals("Invalid password", CredentialCheck.join("username", "", "password123").msg)
assertTrue(CredentialCheck.join("username", "", "password123").fail)

// Password corto
assertEquals("Invalid password", CredentialCheck.join("username", "abc", "password123").msg)
assertTrue(CredentialCheck.join("username", "pass", "password123").fail)

// Contraseñas no coinciden
assertEquals("Passwords do not match", CredentialCheck.join("username", "password123", "password456").msg)
assertTrue(CredentialCheck.join("username", "password123", "password456").fail)

// Credenciales válidas
assertEquals("Your credentials are OK", CredentialCheck.join("username", "password123", "password123").msg)
assertFalse(CredentialCheck.join("username", "password123", "password123").fail)
}
}

0 comments on commit 5e67207

Please sign in to comment.