我目前正在为一个类开发Windows应用商店应用程序(Windows 8),并且在运行NUnit测试时遇到问题。使用NUnit测试Windows 8商店应用程序
我的解决方案/项目设置如下所示:
TheMetroApp.sln
- SQLite的-net.csproj - 类库(Windows应用商店的应用程序)。文件从NuGet中提取。
- DataModel.csproj - 类库(Windows应用商店应用程序)
- UnitTests.csproj - 单元测试库(Windows应用商店应用程序)。 NUnit框架从NuGet中提取。
- TheMetroApp.csproj - 从其中一个Windows SDK示例中提取的项目文件。
Misc。依赖性和公用事业
- 的Windows 8专业版RTM /的Visual Studio 2012 RTM
- ReSharper的7
- NUnit的2.6.1
- SQLite的
UnitTests依赖于并引用DataModel。 DataModel依赖于并引用SQLite-net。我已经添加到UnitTests项目的唯一的一个类包含一些存根NUnit单元测试。据我所知,这些设置正确:
[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是Windows 8 SDK示例项目之一,但在我没有这个项目的任何问题,抛出一些自定义的XAML形式。 。
我的问题是,我试图使用的单元测试运动员都没有工作。
当我尝试使用官方NUnit的86的测试运行(版本2.6.1),我的测试失败,因为证书相关的问题(see here):
UnitTests.TaskSourceTests.CreateTaskTest:
SetUp : System.InvalidOperationException : The process has no package identity. (Exception from HRESULT: 0x80073D54)
的确切同样的原因ReSharper的NUnit的测试运行失败。不幸的是,目前看来目前还没有解决方法。
我也尝试使用Visual Studio 2012内置的测试运行器(通过NUnit Visual Studio Test Adapter)。当我尝试使用运行我的测试“运行所有”,我得到下面的输出:
------ 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,微软的单元测试框架或其他东西。如果我能让NUnit工作,那将会非常棒。
谢谢!
这是一个很好的问题。我认为这是因为反射模型与.NETCore与经典.NET不兼容。也不确定是否可以将.NETCore应用程序加载到Windows桌面模式。本文解释了这些差异:http://blogs.msdn.com/b/dotnet/archive/2012/08/28/evolving-the-reflection-api.aspx – Robert