使用NUnit测试Windows 8商店应用程序

我目前正在为一个类的Windows应用程序应用程序(Windows 8)工作,我在运行NUnit测试时遇到问题。

我的解决方案/项目设置如下所示:

  • TheMetroApp.sln

    • SQLite-net.csproj – 类库(Windowsapp store应用)。 文件从NuGet中提取。
    • DataModel.csproj – 类库(Windowsapp store应用)
    • UnitTests.csproj – unit testing库(Windowsapp store应用)。 NUnit框架是从NuGet中提取的。
    • TheMetroApp.csproj – 从其中一个Windows SDK示例中提取的项目文件。
  • 杂项。 依赖性和实用性

    • Windows 8 Pro RTM / Visual Studio 2012 RTM
    • ReSharper 7
    • NUnit 2.6.1
    • SQLite(根据此处的说明设置)

UnitTests依赖于并引用DataModel。 DataModel依赖于并引用SQLite-net。 我添加到UnitTests项目的唯一内容是包含一些存根NUnitunit testing的单个类。 据我所知,这些设置正确:

[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 results = db.Query( query, task.Id ); Assert.True( results.Contains( task ) ); } } // ...and so on [but with stubs that are basically Assert.Fail( "" )]. #endregion } 

TheMetroApp是Windows 8 SDK示例项目之一,但引入了一些自定义XAML表单。我对此项目没有任何问题。

我的问题是我尝试使用的unit testing运行器都没有工作。

当我尝试使用官方NUnit x86 Test runner(版本2.6.1)时,我的测试由于证书相关问题而失败(请参阅此处) :

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

ReSharper的NUnit测试运行器出于同样的原因失败。 不幸的是,它看起来似乎没有解决方法。

我也尝试使用Visual Studio 2012中内置的测试运行器 (通过NUnit Visual Studio测试适配器 )。 当我尝试使用“全部运行”运行我的测试时,我得到以下输出:

 ------ 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) ========== 

我注意到一些奇怪的事情是,如果我在测试资源管理器中选择一个特定的测试并告诉它运行,我得到一个略有不同的错误消息:

 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. 

这有点令人困惑,因为我安装了NUnit测试适配器。 我在测试适配器的启动板页面上没有看到类似于我的问题。

我不确定我应该从哪里开始。 如果这不起作用,我不介意重新设计我的项目以使用xUnit.net,Microsoft的unit testing框架或其他东西。 如果我可以让NUnit工作,那将是非常棒的。

谢谢!

我有一个Windows 7手机应用程序,你有同样的问题。 我的解决方案是创建一个单独的“链接”项目,该项目使用标准.net库编译代码。 链接的项目与unit testing/ NUnit没有任何问题。

有关更多信息,请参阅以下内容

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

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

我已将应用程序移植到Windows 8,并且运行我的测试用例没有问题。

我在为通用应用程序(W81 + WP81)创建unit testing时遇到了相同的错误消息。 这里唯一的解决方案是停止使用NUnit并仅使用MSTest。