首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用NUnit测试Windows8Store应用程序

用NUnit测试Windows8Store应用程序
EN

Stack Overflow用户
提问于 2012-10-16 22:42:30
回答 2查看 3.8K关注 0票数 15

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

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

  • TheMetroApp.sln

代码语言:javascript
复制
- 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.

  • 其他。依赖关系和实用程序

代码语言:javascript
复制
- 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单元测试的单个类。据我所知,这些设置是正确的:

代码语言:javascript
复制
[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)而失败

代码语言:javascript
复制
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“运行我的测试时,我得到以下输出:

代码语言:javascript
复制
------ 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中选择一个特定的测试并让它运行,我会得到一个稍微不同的错误消息:

代码语言:javascript
复制
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工作的话,那就太棒了。

谢谢!

EN

Stack Overflow用户

发布于 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,运行我的测试用例没有任何问题。

票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12924579

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档