Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing a Windows 8 Store App with NUnit

I'm currently working on a Windows Store Application (Windows 8) for a class and I'm having problems getting my NUnit tests to run.

My Solution/Project setup looks like the following:

  • TheMetroApp.sln

    • SQLite-net.csproj - Class Library (Windows Store Apps). Files are pulled from NuGet.
    • DataModel.csproj - Class Library (Windows Store Apps)
    • UnitTests.csproj - Unit Test Library (Windows Store Apps). NUnit framework is pulled from NuGet.
    • TheMetroApp.csproj - A project file which was pulled from one of the Windows SDK examples.
  • Misc. Dependencies and Utilities

    • Windows 8 Pro RTM/Visual Studio 2012 RTM
    • ReSharper 7
    • NUnit 2.6.1
    • SQLite (Set up per the instructions here)

UnitTests is dependent upon and references DataModel. DataModel is dependent upon and references SQLite-net. The only thing I have added to the UnitTests project is a single class containing some stub NUnit unit tests. As far as I can tell, these are set up correctly:

[TestFixture]
public class TaskSourceTests
{
    #region Private Class Members

    private ITaskSource _taskSource;
    private String _dbPath;

    #endregion

    #region Testing Infrastructure

    [SetUp]
    public void SetUp()
    {
        // This part makes NUnit/ReSharper have problems.
        _dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "UnitTestDatabase.sqlite");
    }

    #endregion

    #region Misc. CRUD stuff

    [Test]
    public void CreateTaskTest()
    {
        // Save the task.
        Task task = new Task( "Some Task", "lol.", DateTime.Now, false );
        _taskSource.Save( task );

        // Confirm that it is in the task db.
        using( SQLiteConnection db = new SQLiteConnection( _dbPath ) )
        {
            const String query = "SELECT * FROM Task WHERE Id = ?";
            IList<Task> results = db.Query<Task>( query, task.Id );
            Assert.True( results.Contains( task ) );
        }
    }

    // ...and so on [but with stubs that are basically Assert.Fail( "" )].

    #endregion
}

TheMetroApp is one of the Windows 8 SDK sample projects, but with some custom XAML forms thrown in. I'm not having any problems with this project.

My issue is that none of the Unit Test runners that I have tried to use are working.

When I try to use the official NUnit x86 Test runner (version 2.6.1), my tests fail due to certificate related issues (see here):

UnitTests.TaskSourceTests.CreateTaskTest:
SetUp : System.InvalidOperationException : The process has no package identity. (Exception from HRESULT: 0x80073D54)

ReSharper's NUnit test runner fails for the exact same reason. Unfortunately, it doesn't look like there is currently a workaround for that.

I have also tried using the test runner built into Visual Studio 2012 (through the NUnit Visual Studio Test Adapter). When I try to run my tests using "Run All", I get the following output:

------ Run test started ------
Updating the layout...

Checking whether required frameworks are installed...

Registering the application to run from layout...

Deployment complete. Full package name: "GibberishAndStuff"

No test is available in C:\Projects\project-name\ProjectName\UnitTests\bin\Debug\UnitTests.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
========== Run test finished: 0 run (0:00:09.4873768) ==========

Something strange I have noticed is that if I select a specific test in the Test Explorer and tell it to run, I get a slightly different error message:

Could not find test executor with URI 'executor://nunittestexecutor/'.  Make sure that the test executor is installed and supports .net runtime version 4.0.30319.18010.

This is kind of perplexing because I have the NUnit Test Adapter installed. I'm not seeing anything similar to my issue on the launchpad page for the test adapter.

I'm not really sure where I should proceed from here. If this doesn't work I don't mind reworking my project to use xUnit.net, Microsoft's unit testing framework or something else. It would be pretty awesome if I could get NUnit working though.

Thanks!

like image 515
Morgan Cabral Avatar asked Oct 16 '12 22:10

Morgan Cabral


1 Answers

I have a Windows 7 Phone app which had the same issue that you have. My solution was to create a separate "linked" project which compiles the code using the standard .net libraries. The linked project will have no issues with unit test / NUnit.

See the following for more information:

http://msdn.microsoft.com/en-us/library/ff921109(v=pandp.40).aspx

http://visualstudiogallery.msdn.microsoft.com/5e730577-d11c-4f2e-8e2b-cbb87f76c044/

I've ported the app to Windows 8 and have no problems running my test cases.

like image 142
raider33 Avatar answered Nov 13 '22 23:11

raider33