如何创建NUnit的测试,ReSharper的? [英] How can I create NUnit tests with ReSharper?

查看:258
本文介绍了如何创建NUnit的测试,ReSharper的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让与C#单元测试。不同的人告诉我,NUnit的去,因为它比MSTest的(显然,我不知道),也有我使用的ReSharper的很好的支持。

I'm trying to get into unit testing with C#. Various people told me to go with NUnit since it's better than MSTest (apparently, I have no idea) and it also has very good support in ReSharper which I'm using.

现在,我从来没有在我的生活写单元测试(包涵,我是一个大学生)。 ReSharper的有,我已经看到别人(随便找过肩)使用了巨大的成功这个漂亮的CreateUnitTests上下文菜单选项。在方法用鼠标右键单击,选择CreateUnitTests和你去那里,将创建一个测试框架。您只需填写重要位。

Now I've never written a unit test before in my life (bear with me, I'm a university student). ReSharper has this nice CreateUnitTests context menu option that I've seen others (casually looking over the shoulder) use to great success. You right-click in a method, select CreateUnitTests and there you go, a test skeleton is created. You just fill in the important bits.

现在,当我尝试一样,ReSharper的要我创建一个新的测试项目......当我让它,它创建(什么我假设)有一个明显MSTest的测试模板MSTest的项目。但我已经有一个类libarary项目,引用nunit.framework,并有一些NUnit的测试是ReSharper的不止愿意跑。尽管如此,它永远只能在特殊的测试计划项目创建MSTest的测试模板,只有永远。

Now when I try the same, ReSharper wants me to create a new Test Project... and when I let it, it creates (what I'm assuming) a MSTest project with obviously a MSTest test template. But I already have a class libarary project which references "nunit.framework" and has a few NUnit tests that ReSharper is more than willing to run. Still, it only ever creates MSTest test templates, and only ever in special "Test Project" projects.

我在做什么错了?我是不是做错了什么可言,或创造与ReSharper的不可能NUnit测试模板?我搜索网,读ReSharper的和NUnit的文档,我仍然无法弄清楚这甚至可能还是什么。

What am I doing wrong? Am I doing something wrong at all, or is creating NUnit test templates not possible with ReSharper? I've searched the net and read the documentation of ReSharper and NUnit and I still can't figure out is this even possible or what.

我会很感激,如果任何人都可以向我提供一种指导使用ReSharper的+ NUnit的。

I'd be grateful if anyone could provide me with a sort of guide to using ReSharper + NUnit.

编辑:我使用ReSharper的4.5和NUnit 2.5.3

I'm using ReSharper 4.5 and NUnit 2.5.3

EDIT2:显然我是白痴。 CreateUnitTests不ReSharper的的一部分,但Visual Studio中的一部分,因此与MSTest的只有永远有效。

Apparently I'm an idiot. CreateUnitTests is not part of ReSharper, but part of Visual Studio and thus only ever works with MSTest.

推荐答案

在您的测试项目,该项目ReSharper的创建,删除提及微软单元测试DLL(我不记得名字了手,但它是一个相当长的名字)。

In your test project which Resharper created, remove the reference to the Microsoft unit testing DLL (I don't recall the name off hand, but it's quite a long name).

然后添加一个新的参考 - nunit.framework.dll中,你会发现它Add Reference对话框的第一个选项卡

Then add a new reference - nunit.framework.dll, you should find it on the first tab of the Add Reference dialog.

添加使用NUnit.Framework 来的单元测试类文件

Add using NUnit.Framework to to the unit test class file.

然后,您需要更改属性:

You then need to change attributes:

[TestClass] to [TestFixture]
[TestMethod] to [Test]

所以,如果你结束了一个MSTest的项目,使用上述步骤获得NUnit的,而不是

So if you end up with a MSTest project, use the above steps to get NUnit instead.

请注意:有原生支持ReSharper的4.5起不MSTest的运行以及NUnit的测试。所以,你可以试试吧。

NOTE: Resharper 4.5 onwards does have native support for running MSTest as well as NUNit tests. So you could try that instead.

这篇关于如何创建NUnit的测试,ReSharper的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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