NUnit Weirdness

PaulPPaulP USMember ✭✭

This is a good one :)

In Xamarin Studio in order to test an async method the test method return type has to be void :

[Test]
public async void GetCarWashesAsync_ShouldReturnCarWashes ()    

In order for the exact same test to work in Visual Studio the return type has to be Task

[Test]
public async Task GetCarWashesAsync_ShouldReturnCarWashes ()    

If in Xamarin Studio the return type is Task the test just gets skipped (project builds but test does not run) and vice-versa.

Full example here :

https://github.com/paulpatarinski/ShouldIWashMyCar/blob/master/Core.Test/GooglePlacesServiceTest.cs

Posts

  • ChaseFlorellChaseFlorell CAInsider, University mod
    edited June 2014

    what if you try something like this?

        [Test]
        public async void GetCarWashesAsync_ShouldReturnCarWashes ()
        {
            // setup
            var googlePlacesService = new GooglePlacesService (new System.Net.Http.HttpClient ());
    
            var location = new Position {
                Latitude = 41.890969,
                Longitude = -87.676392 
            };
    
            // execute
            var results = await googlePlacesService.GetCarWashesAsync (location);
    
            // assert
            Assert.IsNotNull (results );
        }
    
  • PaulPPaulP USMember ✭✭

    That works in Visual Studio, but not in Xamarin Studio. In Xamarin Studio if you put a break point on the Assert it reaches it pauses briefly and continues execution (preventing you from inspecting the object).

    Also I am running Xamarin Studio 5.1 (build 479)

  • ChaseFlorellChaseFlorell CAInsider, University mod
    edited July 2014

    have you tried running it synchronously?

    var results = googlePlacesService.GetCarWashesAsync (location).Result;
    
  • PaulPPaulP USMember ✭✭

    Running it synchronously makes it work in both VS and Xamarin Studio, however I am not able to inspect the variables in Xamarin Studio

    image

Sign In or Register to comment.