Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Tests Not Appearing

I'm using Visual Studio Express 2012 on the Windows 8 Release Preview and I can't seem to get my unit tests to appear in the test explorer.

I have a class called TestApp.Entity, and TestApp.EntityTest...

Here is my code:

namespace TestApp.Entity.Test
{
    using System;
    using System.Net.Http;
    using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
    using TestApp.Domain;

    [TestClass]
    public class EntityTests
    {
        [TestMethod]
        public async void TestObject1Deserialize()
        {
            Uri agencyUri = new Uri("*removed*");
            HttpClient httpClient = new HttpClient();
            HttpResponseMessage response = await httpClient.GetAsync(agencyUri);

            string responseBodyAsText = await response.Content.ReadAsStringAsync();
            List<Agency> agencyList = Deserializers.AgencyDeserialize(responseBodyAsText);

            CollectionAssert.Contains(agencyList, new Agency() { Tag = "*removed*", Title = "*removed*", ShortTitle = "", RegionTitle = "*removed*" });
        }

    }
}

I assume that's all I needed to do, but they still don't appear in the test explorer. Any advice would be helpful.

like image 954
jyanks Avatar asked Sep 27 '12 05:09

jyanks


People also ask

How do I enable unit testing?

Turn live unit testing from the Test menu by choosing Test > Live Unit Testing > Start.

How do you find unit tests?

A typical unit test contains 3 phases: First, it initializes a small piece of an application it wants to test (also known as the system under test, or SUT), then it applies some stimulus to the system under test (usually by calling a method on it), and finally, it observes the resulting behavior.

How do I add unit tests to Xcode project?

Adding a unit test in Xcode If you already have a project, you can add a Unit Testing Bundle to it as well. Go to File > New > Target. Select iOS Unit Testing Bundle and then click Next.


3 Answers

As per Stephen Cleary, "you need to make your unit tests async Task instead of async void for them to work correctly".

This fixed the problem and the tests appeared. It's odd that no errors appeared when I used void, but now I know. Thank you!

like image 92
jyanks Avatar answered Oct 14 '22 15:10

jyanks


I have Visual Studio 2012 and i couldn't see the Tests in Test Explorer,

So I installed the following: NUnit Test Adapter

That fixed the issue for me !

like image 29
dnnyz Avatar answered Oct 14 '22 15:10

dnnyz


Do a rebuild all on the application, including any projects that contain test classes and test methods. They should appear in Test Explorer soon after.

like image 1
akton Avatar answered Oct 14 '22 15:10

akton