测试在Windows 8 Store应用与NUnit的 [英] Testing a Windows 8 Store App with NUnit

查看:372
本文介绍了测试在Windows 8 Store应用与NUnit的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个Windows应用商店的应用程序(Windows 8)的一类,我有问题,让我的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

  • TheMetroApp.sln

  • 在SQLite的-net.csproj - 类库(Windows应用商店的应用程序)。文件从的NuGet拉。
  • DataModel.csproj - 类库(Windows应用商店的应用程序)
  • UnitTests.csproj - 单元测试库(Windows应用商店的应用程序)。 NUnit的框架是从的NuGet拉。
  • TheMetroApp.csproj - 这是从Windows SDK中的例子之一拉到一个项目文件

其它。相关性和实用程序

Misc. Dependencies and Utilities

  • 的Windows 8专业版RTM /的Visual Studio 2012 RTM
  • ReSharper的7
  • NUnit的2.6.1
  • 在SQLite的(设置各的说明<一href="http://timheuer.com/blog/archive/2012/08/07/updated-how-to-using-sqlite-from-windows-store-apps.aspx">here)
  • Windows 8 Pro RTM/Visual Studio 2012 RTM
  • ReSharper 7
  • NUnit 2.6.1
  • SQLite (Set up per the instructions here)

单元测试取决于和引用的DataModel。 DataModel的是取决于和引用的SQLite网。我已经加入到单元测试项目中的唯一一件事就是含有一些残余部分NUnit的单元测试的类。据我所知,这些都是正确设置:

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是Windows 8 SDK示例项目之一,但扔了进去。我并没有把这个项目的任何问题,一些自定义的XAML形式。

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.

我的问题是,没有,我曾尝试使用正在使用的单元测试亚军。

当我尝试使用官方NUnit的86的测试运行(2.6.1版本),我的测试失败,因为证书的相关问题<一href="http://social.msdn.microsoft.com/Forums/en-US/toolsforwinapps/thread/449635cd-6aad-4d89-95a7-be7444d48f98">(see这里):

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的的NUnit的测试运行失败的确切同样的道理。不幸的是,它看起来并不像有目前的解决方法的。

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

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

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.

这是一种令人费解,因为我已经安装了NUnit的测试适配器。我没有看到任何类似我的问题的测试适配器启动板页面上。

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.

我真的不知道,我应该从这里着手。如果这不工作,我不介意返工​​我的项目使用xUnit.net,微软的单元测试框架,或别的东西。这将是pretty的真棒,如果我能得到的NUnit虽然工作。

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.

谢谢!

推荐答案

我有一个Windows 7 Phone应用其中有你有同样的问题。我的解决方案是创建一个单独的链接项目,该项目编译c。使用标准的.NET库$ C $。链接项目将与单元测试没有问题/ NUnit的。

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/

我移植应用程序到Windows 8,并在运行我的测试情况下,没有任何问题。

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

这篇关于测试在Windows 8 Store应用与NUnit的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆