我目前正在为一个类开发一个Windows应用程序(Windows8),在运行我的NUnit测试时遇到了问题。
我的解决方案/项目设置如下所示:
- 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.
- Windows 8 Pro RTM/Visual Studio 2012 RTM
- ReSharper 7
- NUnit 2.6.1
- SQLite (Set up per the instructions [here](http://timheuer.com/blog/archive/2012/08/07/updated-how-to-using-sqlite-from-windows-store-apps.aspx))
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是Windows8SDK示例项目之一,但附带了一些自定义XAML表单。我在这个项目上没有任何问题。
我的问题是,我尝试使用的单元测试运行程序都没有工作。
当我尝试使用正式的NUnit x86测试运行程序(Version2.6.1)时,我的测试由于与证书相关的问题(see here)而失败
UnitTests.TaskSourceTests.CreateTaskTest:
SetUp : System.InvalidOperationException : The process has no package identity. (Exception from HRESULT: 0x80073D54)ReSharper的NUnit测试运行程序由于完全相同的原因而失败。不幸的是,目前似乎还没有一个解决办法。
我还尝试使用内置到Visual 2012中的测试运行程序(通过NUnit Visual Studio Test Adapter)。当我尝试使用"Run“运行我的测试时,我得到以下输出:
------ 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) ==========奇怪的是,如果我在test中选择一个特定的测试并让它运行,我会得到一个稍微不同的错误消息:
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测试适配器。在测试适配器的launchpad页面上,我没有看到类似于我的问题。
我不太确定从这里该从哪里出发。如果这样做不起作用,我不介意用xUnit.net、微软的单元测试框架或其他东西来重新设计我的项目。不过,如果我能让NUnit工作的话,那就太棒了。
谢谢!
发布于 2012-11-27 17:14:09
我有一个Windows 7手机应用程序,有同样的问题,你有。我的解决方案是创建一个单独的“链接”项目,它使用标准的.net库编译代码。链接的项目将没有单元测试/ 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,运行我的测试用例没有任何问题。
发布于 2015-02-15 16:41:39
在为通用应用程序(W81 + WP81)创建单元测试时,我刚刚碰到了相同的错误消息。这里唯一的解决方案是停止使用NUnit,只使用MSTest。
https://stackoverflow.com/questions/12924579
复制相似问题