Android Open Source - CalculatorTest Calculator Test






From Project

Back to project page CalculatorTest.

License

The source code is released under:

MIT License

If you think the Android project CalculatorTest listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.javiermunoz.calculatortest.activityinstumentation;
//from  w  w w  . j ava2  s. co  m
import android.support.test.espresso.action.ViewActions;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;

import com.javiermunoz.calculatortest.R;
import com.javiermunoz.calculatortest.ui.home.CalculatorActivity;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static org.hamcrest.Matchers.allOf;

/**
 * Created by javier.munoz on 23/12/14.
 */
@LargeTest
public class CalculatorTest extends ActivityInstrumentationTestCase2<CalculatorActivity> {

    public CalculatorTest() {
        super(CalculatorActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        getActivity();
    }

    public void testSumNumbers() {
        onView(allOf(withText("5"), withId(R.id.buttonCalculator))).perform(ViewActions.click());
        onView(allOf(withText("+"), withId(R.id.buttonCalculator))).perform(ViewActions.click());
        onView(allOf(withText("7"), withId(R.id.buttonCalculator))).perform(ViewActions.click());
        onView(allOf(withText("="), withId(R.id.buttonCalculator))).perform(ViewActions.click());
        onView(allOf(withId(R.id.resultTextView))).check(matches(withText("12")));
    }
}




Java Source Code List

com.javiermunoz.calculatortest.ApplicationTest.java
com.javiermunoz.calculatortest.activityinstumentation.CalculatorTest.java
com.javiermunoz.calculatortest.ui.home.ButtonsAdapter.java
com.javiermunoz.calculatortest.ui.home.CalculatorActivity.java