mardi 25 août 2015

Why does this unit test throw an "Element not found" exception?

I have created a very basic unit test for my C# project. The application is a thick client based on UWP so I am using Universal unit tests. I run the test and it fails with a System.Exception: Element not found message. It also says

GetForCurrentView must be called on a thread that is associated with a CoreWindow

I've added the main project as a reference to the test project.

Here is a minimum working example:

namespace MyProjectTests
{
    [TestClass]
    public class ExampleObjectTest
    {
        private ExampleObject exampleObject;

        [TestInitialize]
        public void Setup()
        {
            exampleObject = new ExampleObject();
        }

        [TestMethod]
        public void RequestParametersIsNotNullTest()
        {
            Dictionary<string, string> parameters = exampleObject.MethodThatReturnsDictionary();
            Assert.IsNotNull(parameters);
        }
    }
}

This method does not return null but the test still fails. Is there further setup required in order to ensure this test passes?

Aucun commentaire:

Enregistrer un commentaire