Skip to content

Commit

Permalink
Merge pull request #15 from Mofazzal874/Mofazzal
Browse files Browse the repository at this point in the history
Instrumented/UI testing on MycartsFragmentTest is added...…
  • Loading branch information
Mofazzal874 committed May 25, 2024
2 parents 3576d07 + dcc03a7 commit eba76fd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
4 changes: 1 addition & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies {
implementation("com.google.firebase:firebase-firestore:24.9.1")
implementation("com.google.firebase:firebase-storage:20.3.0")
implementation("androidx.test.ext:truth:1.5.0")
implementation("androidx.test.espresso:espresso-intents:3.5.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
implementation ("com.makeramen:roundedimageview:2.3.0")
implementation ("com.airbnb.android:lottie:4.1.0")
Expand Down Expand Up @@ -79,9 +80,6 @@ dependencies {

//dependencies for ui_test
androidTestImplementation("androidx.test:rules:1.5.0")
androidTestImplementation("org.mockito:mockito-core:3.12.4")
androidTestImplementation("org.mockito:mockito-android:3.12.4")
androidTestImplementation("androidx.test.espresso:espresso-intents:3.4.0")
// AndroidX Test - Instrumentation Testing
androidTestImplementation("androidx.test:runner:1.5.2")
androidTestImplementation("androidx.test:rules:1.5.0")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.example.projecto.activities;

import androidx.test.espresso.intent.Intents;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.test.core.app.ActivityScenario;
import androidx.test.core.app.ApplicationProvider;

import com.example.projecto.MainActivity;
import com.example.projecto.R;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.intent.Intents.intended;
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static androidx.test.espresso.matcher.ViewMatchers.withId;

@RunWith(AndroidJUnit4.class)
public class MycartsFragmentTest {

@Rule
public ActivityScenarioRule<MainActivity> activityScenarioRule =
new ActivityScenarioRule<>(MainActivity.class);

@Rule
public FirebaseAuthRule firebaseAuthRule = new FirebaseAuthRule();

@Before
public void setUp() {
Intents.init();
}

@After
public void tearDown() {
Intents.release();
}

@Test
public void testBuyNowButton_opensAddressActivity() {
// Launch the MainActivity
ActivityScenario<MainActivity> scenario = activityScenarioRule.getScenario();
scenario.onActivity(activity -> {
// Find the NavController from the activity
NavController navController = Navigation.findNavController(activity, R.id.nav_host_fragment_content_main);
// Navigate to MycartsFragment
navController.navigate(R.id.nav_mycarts);
});

// Perform click on buy_now button
onView(withId(R.id.buy_now)).perform(click());

// Verify that the AddressActivity is launched
intended(hasComponent(AddressActivity.class.getName()));
}
}

0 comments on commit eba76fd

Please sign in to comment.