Michael Ridland: New Xamarin.Forms eCourse

I’ve been blessed in my career, having the opportunity to join the Xamarin world over 4 years ago. In my 4 years of Xamarin I’ve been able to publish over 8 Xamarin Applications into the App Stores and work on million dollar Xamarin projects. I’ve been a Xamarin.Forms fan since its first release and released […]

The post New Xamarin.Forms eCourse appeared first on Michael Ridland.

Xamarin: Webinar Recording: Go Mobile with Xamarin and Azure

Since 2014, adults spend more time on mobile devices than laptops and desktops, and over 75% of them utilize smartphones for internet access. Today’s apps are being defined by mobile and the cloud, but integrating the two together is a challenge many developers face. Your mobile app strategy also requires fast, fully native experiences and […]

The post Webinar Recording: Go Mobile with Xamarin and Azure appeared first on Xamarin Blog.

Xamarin: Xamarin Podcast: Reviewing iOS 9, tvOS, and More!

This week on the Xamarin Podcast, Mike and I catch you up on all the latest announcements from Apple’s special event on September 9th, including iOS 9, tvOS, the iPad Pro and Apple Pencil, Apple Watch updates, and thoughts on our favorite Apple keynote speaker, Eddie Q. Subscribe or Download Today Knowing the latest in .NET, C#, […]

The post Xamarin Podcast: Reviewing iOS 9, tvOS, and More! appeared first on Xamarin Blog.

Adam J Wolf: Weekly Xamarin Newsletter Issue #59

Xamarin Evolve 2016: Call For Participation Joseph Hill, from Xamarin Inc., opens the call for presentations for Evolve 2016. Upcoming speaking engagements and travels! Laurent Bugnion has some awesome talks coming up; check them out. Animating a Grid in Xamarin.Forms Krystin Stutesman, from Xamarin Inc., shows off some cool Xamarin.Forms animations. Add a Conversation to […]

The post Weekly Xamarin Newsletter Issue #59 appeared first on Syntax is my UI.

Greg Shackles: Testing Xamarin Apps: Getting Started with xUnit

It’s no secret that I’m a big proponent of testing, and lately I’ve been getting a lot of questions around how to approach getting started and what technologies to use. While I have a good amount of content coming out around this, some already announced, some to be announced soon, I thought I would also try to take some time to put together a few posts on the subject as well.

In this post I’m going to focus on setting up unit testing for Xamarin apps using the xUnit framework. If you’ve followed my testing content in the past, you might remember me recommending the usage of NUnitLite a few years back as the framework of choice. At the time that was the best option, but these days xUnit has a far superior cross-platform story (major props to Oren Novotny for helping drive that forward!), in addition to just being a more modern framework in general. The biggest downside, at least at the time of writing this, is that there isn’t any sort of integration with Xamarin Studio, but hopefully that story will improve as well.

Creating The Test Project

To start off, create a portable class library for your tests to live in. Alternatively you could also go with a shared project if you’d prefer, but unless you need it I recommend sticking with a PCL. Using a PCL will enable you to easily run the tests in any xUnit test runner, such as Visual Studio, the command line, iOS, Android, or Windows Phone.

Once that’s created, add the xUnit.net NuGet package:

NuGet

As of the time of this post I recommend installing the pre-release version of xUnit, as pictured here, which brings with it improved Mono support. Similiarly, Xamarin’s Alpha channel currently ships with an updated version of Mono that improves xUnit support. Both of these should hit the stable channels soon so this recommendation will be short-lived, but I wanted to point it out in the meantime.

In addition to the main xUnit package, also go ahead and install the console runner package. If you’d also like to run the tests in Visual Studio, you can add the Visual Studio runner package as well.

With those installed, let’s create some tests:

using System;  
using System.Threading.Tasks;  
using Xunit;

namespace TestDemo  
{
    public class TestsAreGood
    {
        [Fact]
        public void ThisShouldPass()
        {
            Assert.True(true);
        }

        [Fact]
        public async Task ThisShouldFail()
        {
            await Task.Run(() => { throw new Exception("boom"); });
        }
    }
}

Obviously these are pretty trivial, but as you can see xUnit has support for async tests. In fact, it has much better support for async tests than the version of NUnit that ships with Mono/Xamarin Studio, which is another awesome advantage to going with xUnit.

Runner: Console

Now that we have tests, let’s start by running them from the console:

> mono packages/xunit.runner.console.2.1.0-rc2-build3176/tools/xunit.console.exe TestDemo/bin/Debug/TestDemo.dll

xUnit.net Console Runner (32-bit .NET 4.0.30319.17020)  
  Discovering: TestDemo
  Discovered:  TestDemo
  Starting:    TestDemo
    TestDemo.TestsAreGood.ThisShouldFail [FAIL]
      System.Exception : boom
      Stack Trace:
        <trimmed>
  Finished:    TestDemo
=== TEST EXECUTION SUMMARY ===
   TestDemo  Total: 2, Errors: 0, Failed: 1, Skipped: 0, Time: 0.100s

As expected, we had one test pass and one fail. I suggest creating a script to allow you to easily and quickly run these tests to lower the friction to running the tests going forward. You could even set up a monitor on the DLL file and automatically re-run your tests each time you compile!

Runner: iOS

The console runner is great and all, but we’re doing mobile development here, so it really only matters if our code works in that environment. Lucky for us the xUnit cross platform story is awesome, so it’s nice and easy to get these tests running there as well.

Start off by creating a new single view iOS project, and then delete the generated storyboard and view controller files. Also make sure go into your Info.plist file and remove the “main interface” references to the storyboard. Next, add a project reference to the main PCL test project from before.

With that set up, add the xUnit.net for Devices NuGet package:

NuGet

That NuGet package will add a new file to your solution named AppDelegate.cs.txt. Go ahead and copy the contents of that file and replace the contents of AppDelegate.cs with it. After that you can go ahead and delete the AppDelegate.cs.txt file if you like.

if you take a look in the code now in AppDelegate.cs, you’ll see some references to a function named AddTestAssembly(). This is what you can use to tell xUnit which assemblies to scan for tests. By default it will include an instruction to scan the current assembly, but in our case that won’t return anything since our tests are in a separate library. If you had been using a shared code project, this default scan would be sufficient.

Replace the existing AddTestAssembly() call with:

AddTestAssembly(typeof(TestsAreGood).Assembly);  

Set the iOS project as the solution’s startup project and run it:

iOS Runner

Your tests are now running in iOS without having to change anything! You can run them either in the simulator or on a device to validate that your code truly works across the board.

Runner: Android

With iOS out of the way, let’s also get these tests running on Android. The process here is very similar to setting up iOS. Create a new Android project, add a reference to the test library, and add the same xUnit.net for Devices NuGet package that we added to iOS.

Just like with iOS, the package will add a MainActivity.cs.txt file to your solution. Take the contents of that file and overwrite what’s in MainActivity.cs. Update the AddTestAssembly() call in there with the same line as before:

AddTestAssembly(typeof(TestsAreGood).Assembly);  

Set the Android runner as the startup project, fire up your favorite emulator or device, and voilà!

Summary

Setting up these runners are just a one-time thing, as they will continue to pick up new tests you add each time you run them. With just a few minutes of effort you can set up an environment where not only can you verify that your code runs properly on the full .NET or Mono frameworks, but also that they run on the device environments that really count here. In future posts I’ll explore some other tips for unit testing your apps, as well as step into other areas like UI testing, Test Cloud, and more.

Xamarin: Add a Conversation to your Android App with Voice Interactions

High app engagement rates don’t have to be difficult to achieve. By adding a few additional touches to your app, your users will want to come back time and time again. Google introduced Voice Actions to the Android Google app, enabling users to speak to their device to easily launch apps and allowing developers to […]

The post Add a Conversation to your Android App with Voice Interactions appeared first on Xamarin Blog.

James Montemagno: See Me Code & Present In Person This Fall!

Sure, I have been live coding all over the interwebz for the last month and will be doing so again this Friday on MVVM Light, but what about seeing some live coding in person? Well you are in luck as I have a super crazy schedule once again flying all over the beautiful US of A! Over the next two months I will be giving sessions, dev days, workshops, webinars, and sooooo much more! I always keep the right side of the blog up to date with where I am at, but here is a nice extended view:

  • 9/24 8AM PDT: Free online webinar: Visualizing data with Xamarin & Syncfusion
  • 10/6-9: Las Vegas, NV – Amazon AWS re:Invent presenting a full 2 hours workshop on integrating AWS Mobile SDK into Xamarin applications!
  • 10/3: Portland, OR – Xamarin Dev Days – Full day of free hands on learning, hacking, and exploring of all things Xamarin!
  • 10/10: Boston, MA – Xamarin Dev Days – Full day of free hands on learning, hacking, and exploring of all things Xamarin!
  • 10/24: Vancouver, BC – Xamarin Dev Days – Full day of free hands on learning, hacking, and exploring of all things Xamarin!
  • 10/26-27: Dallas, TX – .NET Unboxed – Super new and exciting conference where I will be talking all about Plugins for Xamarin and Windows for rapid application development!
  • 10/29: Las Vegas, NV – DEVIntersection – Back to Vegas for a FULL day workshop on Building cross-platform mobile apps with Xamarin.Forms!
  • 11/16-20: Orlando, FL – VS Live! Orlando – Before the holidays it is time for VS Live where I am super crazy excited to be talking all about going mobile with Xamarin and also a full session on Automated User Interface testing!!

This is really just the start though! If you are a user group leader in any of these areas and are looking for a presentation let me know! Reach out and DM me on twitter and I will let you know if I am in town. I hope to see you really soon in person at one of these awesome events!

Xamarin: Live Webinar: Navigating iOS 9 and Android M for the Enterprise

The new iOS 9 and soon-to-be released Android 6.0 Marshmallow mobile platforms have very different visions for mobile computing, yet enterprises need to fully support both for successful customer engagement and business transformation. Navigating their rapidly evolving roadmap and the increasing iOS hardware diversity presents challenges to knowing what your mobile strategy to take. In […]

The post Live Webinar: Navigating iOS 9 and Android M for the Enterprise appeared first on Xamarin Blog.