JUnit-XML based Espresso report
Using the terminal, you can create JUnit-XML based reports from Espresso and upload them to Test Management.
Executing a Test Case with Espresso
You can initiate an Espresso project with this git repository. Use this sample code to execute a Test Case.
@RunWith(AndroidJUnit4.class)
@LargeTest
public class EspressoAndroidTest {
@Rule
public ActivityScenarioRule<MainActivity> activityRule =
new ActivityScenarioRule<>(MainActivity.class);
@Test
public void correctWordMatch() {
onView(withText("Hello World!")).check(matches(isDisplayed()));
}
@Test
public void wrongWordMatch() {
onView(withText("Hello world!")).check(matches(isDisplayed()));
}
}
Create test report with Espresso
Espresso by default generates a JUnit-XML report. Run the following command to execute test run and generate JUnit-XML report.
./gradlew connectedAndroidTest
Sample JUnit-XML report generated from Espresso.
<?xml version='1.0' encoding='UTF-8' ?>
<testsuite name="com.example.espressosample.EspressoAndroidTest" tests="2" failures="1" errors="0" skipped="0" time="6.207" timestamp="2023-07-04T08:10:26" hostname="localhost">
<properties>
<property name="device" value="Pixel_3a_API_33_arm64-v8a(AVD) - 13" />
<property name="flavor" value="" />
<property name="project" value=":app" />
</properties>
<testcase name="listGoesOverTheFold" classname="com.example.espressosample.EspressoAndroidTest" time="2.557" />
<testcase name="wrongWordMatch" classname="com.example.espressosample.EspressoAndroidTest" time="2.938">
<failure>androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: an instance of android.widget.TextView and view.getText() with or without transformation to match: is "Hello world!"
View Hierarchy:
....
....
....
</failure>
</testcase>
</testsuite>
Steps to upload the JUnit-XML test report
Open the project directory in the Terminal and load the variables.
export TEST_MANAGEMENT_API_TOKEN="*************28a42"
export TEST_MANAGEMENT_PROJECT_NAME="<Project Name>"
export JUNIT_XML_FILE_PATH="<Report Path>"
export TEST_RUN_NAME="<Test Run Name"
TEST_MANAGEMENT_API_TOKEN
from the Active API Key section in the Settings of BrowserStack Test Management.
Upload the JUnit-XML test report using curl
command.
curl -k -X POST https://test-management.browserstack.com/api/v1/import/results/xml/junit \
-u $TEST_MANAGEMENT_API_TOKEN \
-F project_name="$TEST_MANAGEMENT_PROJECT_NAME" \
-F "file_path=@$JUNIT_XML_FILE_PATH" \
-F test_run_name="$TEST_RUN_NAME"
cURL
command until you get the response back.
You can also upload JUnit-XML test report with Espresso using CI/CD.
Access the test run report from the console generated URL
After your report is successfully uploaded, you see a message similar to the following in your terminal. This message also generates a URL with "url"
parameter that you can use to access your automated test run.
{"message":"File uploaded successfully.","url":"https://test-management.browserstack.com/projects/<project id>/test-runs/<test run id>","success":true}
View test run report in Test Management
- Log in to the BrowserStack Test Management dashboard.
- Select the relevant project that has the test report uploaded.
- Click Test Runs.
- Open the Test Run generated from automation test exectution.
- You will find all the test cases with their respective results here.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!