DevOps for IoT with Win10 IoT Core, UWP, and VSTS

We often get asked how to do CI/CD for IoT apps using Win10 IoT Core. If you’ve been considering or using Win10 IoT Core, then read on.

The Visual Studio Test Platform that ships with Visual Studio 15.6 RTW now supports Testing on Win10 IoT Core.

Continuous Integration (CI) and Continuous Delivery (CD) are key practices in DevOps. Integrations are frequent, and verified with an automated build that runs automated tests to detect integration errors as soon as possible. The workflow might look as follows:
(1) A developer commits changes to the application’s repo.
(2) A build gets triggered automatically.
(3) Automated tests are executed as part of the build process.
(4) After a successful build, a release is triggered that in turn ensures that the application is deployed to the target device.
(5) The application is then monitored in actual use and insights and learnings are fed back into the pipeline, providing a virtuous feedback loop.

The building blocks for such a CI/CD system for IoT applications would be Win10 IoT Core as the IoT Platform, UWP for the application, and Visual Studio Team Services (VSTS) as the orchestration pipeline. There might be multiple ways to get the application deployed onto the target device. For example, the application might initially be part of the image that is flashed onto the device, and subsequently be released to the store for over-the-air update onto the device; or periodically the entire image on the device might be updated over-the-air. Nevertheless, “testing” was a gap when it came to setting up such a pipeline. Not anymore. The vstest platform that ships with Visual Studio 15.6 RTW bridges this gap by providing first class support for testing on Win10 IoT Core.

Walkthrough of Testing a Win10 IoT Core application
Let’s walkthrough testing a sample UWP IoT application. Here is the application and setup we will be using:
(1) A Raspberry Pi 3 ARM device booted with Win10 IoT Core Fall Creators Edition, with an LED wired up to the GPIO, and the device tethered using ethernet. See the diagram here for connecting the LED.
(2) A UWP IoT application built for ARM and deployed to the remote ARM device. The application can light up the LED.
(3) A UWP test application also built for ARM and deployed to the remote ARM device, and that can drive the app in (2).

Here is the sample application code:
Win10_IoT_Core.sln is the solution.
LED.cs has the methods to ON/OFF the LED.
UnitTest.cs has the corresponding test methods.

Go ahead, clone or download the repo, and open the solution in Visual Studio 15.6 RTW.

Visual Studio IDE integration
There are several points to notice from an IDE-integration perspective:
(1) Test are discovered in real-time, and shown in the Test Explorer.
(2) Since we are targeting ARM based devices, the solution platform can be set appropriately, and in this case is set to ARM.
(3) The Raspberry Pi 3 device is using tethered ethernet. The deployment target can be specified as “Remote Machine” and configured to the IP address of the device name.
(4) You can then build the solution, and execute tests and/or debug tests!

If you got the connections correct, you will have seen the LED glow.

Visual Studio Team Services integration
In VSTS CI, you can use the built-in Universal Windows Platform build template, and the Visual Studio Test task.

Here are the steps to build and execute the tests:
(1) Parameters: set the Solution to build to ‘Win10_IoT_Core/Win10_IoT_Core.sln’
(2) Variables: set the BuildPlatform variable to ARM
(3) NuGet restore step: set the ‘Path to solution’ field to ‘Win10_IoT_Core/Win10_IoT_Core.sln’, and select ‘Use packages from’
(4) Build step: set it to Visual Studio 2017 (NOTE: you will need at least Visual Studio 15.6 RTW)
(5) VsTest step: set the ‘Test assemblies’ field to ‘**\’, and set the ‘Other console options’ field to ‘/framework:FrameworkUap10 — RunConfiguration.TargetDevice=$(deviceIP)’, where (deviceIP) is the IP address of the target remote device.

Here is how the build definition would look:

Queue a build, and voila …

Build completed, tests run, and test results published!

There are several points to notice from a VSTS CI integration perspective:
(1) The default UWP build template can be used without modification.
(2) The default VsTest task can be used without modification.
(3) The test outcomes are fully integrated into the build summary view and the test details report.
(4) Code coverage is not yet supported.

.NET Native Tool chain, and pure native UWP apps
As you will have noticed, this walkthrough illustrates the workflow for a managed UWP application in the Debug configuration. The Release configuration will engage the .NET Native Tool chain. Or, you could have written a native C++ UWP. All of these are supported as well.

The Visual Studio Test Platform now supports Testing on Win10 IoT Core, and is fully integrated into both the Visual Studio IDE and VSTS.
CI in DevOps for IoT is now a reality.

Try it out, and let us know. We are eager to hear your feedback.
The future of DevOps for IoT is bright.