Page 30 - MSDN Magazine, December 15, 2017
P. 30
yourDeviceSetdefinitions.Figure2showsthehundredsofAndroid deviceconfigurationsavailable.Youcansearchandfilterbyformfac- tor, OS version, CPU, device tier, memory, manufacturer and name.
Write tests. The App Center recommendation is to use the testing framework native to the platform. Espresso is the recom- mended framework for Android. For detailed documentation of Espresso, see bit.ly/2mkW6WZ.
The application and tests need to be updated to run in App Center before you upload them. App Center provides a ReportHelper object that aids in navigating the test report. To make the Report- Helper available at compile time for Espresso tests, include the following dependency in the application gradle file:
dependencies { androidTestImplementation(‘com.xamarin.testcloud:espresso-support:1.1’)
}
Add the Test Cloud imports to your test classes:
import com.xamarin.testcloud.espresso.Factory; import com.xamarin.testcloud.espresso.ReportHelper;
Instantiate the ReportHelper in each test class:
@Rule
public ReportHelper reportHelper = Factory.getReportHelper();
Use the ReportHelper to label the test steps. App Center will annotate the test report with the labels and capture a screenshot of the running app at that point in the test. Use the @After anno- tation to include a label at the end of the testing. If a test fails, the @After screenshot shows the final state.
grouped.Youcanhavetestpackagesfocusedondifferentareasof functionality and reuse device collections with different test pack- ages. Click on New Test run and create a new device collection, or select one you’ve already defined. Specify the test series label, system language of the devices and the test framework. App Center now displays instructions for using the CLI to upload the test files and initiate the test run. Copy the command from the portal and paste it into your shell. Customize the parameters for your local setup.
You can have test packages focused on different areas
of functionality and reuse device collections with different test packages.
Here’s the command for uploading my locally built packages and running the tests against my latest-Android device set. The results are part of the main-activity test series:
This can be extremely helpful in figur- ing out why a test run failed.
@After
public void TestComplete() {
reportHelper.label(“Test Complete”); }
Compile. To run the tests on devices in the cloud requires upload- ing the application package and the test package. Create them both with the following commands:
gradlew assembleDebug
gradlew assembleDebugAndroidTest
Install the CLI. To upload and ini- tiate test runs requires the App Center CLI. To run the CLI, you need at least version 6.3 of Node.js (nodejs.org). Install the CLI using npm:
npm install -g appcenter-cli
Log in to App Center:
appcenter login
Youwillberedirectedtothebrowser to complete the login and get an auth token for the CLI. The CLI is accessing the App Center REST API. The same auth token can be used to access the API directory.
Define a Test run. In the Test area, clickonTestrunstoseethehistoryand status of tests. A test run is the combi- nation of a test package run on a device collection.Youspecifyatestserieslabel for each test run so that results can be
Figure 2 New Device Set
26 msdn magazine
App Center