resharper 可以跳转到包含单元测试的文件吗?

发布于 2024-12-05 12:17:10 字数 214 浏览 0 评论 0原文

是否可以以某种方式链接或使用某种约定,以便我可以在给定类的单元测试之间跳转?

另外,创建在接口和实现之间跳转的快捷方式?

(键盘快捷键)

示例:

IUserService 用户服务 UserServiceTests

如果我能以某种方式将它们链接在一起,这样我就可以在当前位于其中任何一个文件中时跳转到其中任何一个文件,那就太好了。

Is it possible to somehow link or use some convention so I can jump between my unit tests for a given class?

Also, creating short cuts for jumping between the interface, the implementations?

(keyboard shortcuts)

Example:

IUserService
UserService
UserServiceTests

It would be great if I can somehow link these together so I can jump to any of these files while in any one of them currently.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

孤独陪着我 2024-12-12 12:17:10

我刚刚在 TestLinker(ReSharper 2016.1 扩展)中实现了该功能。可以从 ReSharper Gallery 安装。

演示

I just implemented that feature in TestLinker, which is a ReSharper 2016.1 extension. It is available to install from the ReSharper Gallery.

Demo

淡写薰衣草的香 2024-12-12 12:17:10

<块引用>

是否可以以某种方式链接或使用某些约定,以便我可以在给定类的单元测试之间跳转?

要在给定类的单元测试之间跳转,请在类名称上启动 ReSharper 的查找用法,一旦查找结果工具窗口中出现结果,请将它们分组一种有助于关注代码库特定部分的使用情况的方法 - 例如,按项目和类型。这将让您检测测试项目中的用法。从那里,您可以快速从查找结果跳转到代码中的实际用法。作为替代方案,您可以使用 ReSharper 的转到符号的用法,其工作方式类似,但在弹出菜单中显示搜索结果,而不是将其刷新到查找结果

如果您的测试类包含显示它们所覆盖的业务逻辑的元数据,这将有助于更好地区分您所需的用法。例如,如果您使用 MSpec,则测试类将标有 Subject 属性: [Subject(typeof (MyCoveredClass))] 这很方便,因为此属性中的用法非常明显,导航到它们将直接引导您的测试类的声明:
查找涵盖特定类的 MSpec 测试类

对于 NUnit 和 MSTest,这有点复杂,因为它们的属性将字符串作为参数,如下所示:[TestProperty("TestKind", "MyCoveredClass")]。为了找到 MyCoveredClass 的此类用法,您必须使用 ReSharper 的高级查找用法并打开文本出现选项。

<块引用>

此外,创建在界面和实现之间跳转的捷径?

至于在继承链中跳转,ReSharper 提供了多个选项来执行此操作,包括类型层次结构(ReSharper > Inspect > Type Hierarchy)和转到实现(ReSharper > ; 导航 > 转到实现):

使用转到实现和/或类型在整个继承链中导航层次结构

Is it possible to somehow link or use some convention so I can jump between my unit tests for a given class?

To jump between unit tests for a given class, launch ReSharper's Find Usages on the class name, and as soon as you have results in the Find Results tool window, group them in a way that helps focus on usages in a particular part of your code base - for example, by project and type. This will let detect usages in your test project. From there, you can quickly jump from Find Results to actual usages in code. As an alternative, you can use ReSharper's Go to Usages of Symbol that works in a similar way but displays search results in a pop-up menu instead of flushing them to Find Results.

If your test classes contain metadata showing which business logic they're covering, this would help even better in differentiating the usages you need. For example, if you're using MSpec, test classes are marked with the Subject attribute: [Subject(typeof (MyCoveredClass))] This is handy because usages within this attribute are very visible, and navigating to them leads you directly to declarations of your test classes:
Find MSpec test classes that cover a particular class

With NUnit and MSTest, this is a bit more complicated as their attributes take strings as parameters, like this: [TestProperty("TestKind", "MyCoveredClass")]. In order to find such a usage of MyCoveredClass, you'll have to use ReSharper's Find Usages Advanced and turn on the Textual occurrences option.

Also, creating short cuts for jumping between the interface, the implementations?

As to jumping within an inheritance chain, ReSharper provides multiple options to do that, including Type Hierarchy (ReSharper > Inspect > Type Hierarchy) and Go to Implementation (ReSharper > Navigate > Go to Implementation):

Navigating throughout inheritance chains with Go to Implementation and/or Type Hierarchy

妞丶爷亲个 2024-12-12 12:17:10

正如已经提到的,您可以使用 TestCop ReSharper 插件(图库链接)。

它通过使用正则表达式来识别类名和命名空间,将被测类与测试装置联系起来。您可以自定义这些以满足您的需求,但我发现需要进行大量的试验和错误才能在现有代码上实现这一点。

全部设置完毕后,您可以使用键盘快捷键来回切换。它还可以为您执行创建 TestFixture 或类等操作。

As has already been mentioned you can do this using the TestCop ReSharper plugin (gallery link).

It ties the class under test to the test fixture by using regular expressions to identify class names and namespaces. You can customise these to fit your needs, but I found there to be a fair amount of trial and error to get this right on existing code.

Once it's all set up you can go back and forth with a keyboard shortcut. It can also do things like create the TestFixture or the class for you.

自找没趣 2024-12-12 12:17:10

除了浏览用法列表之外,ReSharper 没有特定的“转到测试/代码”功能。

但是,测试驱动.NET 具有此功能,它使用命名约定来查找测试/代码对等点,以便您可以来回翻转。

此外,还创建了在界面之间跳转的快捷方式,
实施?

ReSharper有这个功能。使用 Visual Studio 方案:

  • Alt + Home 导航到类的基类,如果有多个类,上下文菜单将列出它们
  • Alt + End 沿继承层次结构向下导航,其行为类似于 Alt + Home

Ctrl + U 和 Ctrl + Alt + B 分别相当于 ReSharper 2.x / IDEA 方案。

ReSharper doesn't have a specific Goto Test/Code feature other than navigating through the list of usages.

However, TestDriven.NET has this feature which uses naming conventions to find the Test/Code peer such that you can flip back and forth.

Also, creating short cuts for jumping between the interface, the
implementations?

ReSharper has this feature. Using the Visual Studio scheme:

  • Alt + Home navigates to the class' base, in case there are more than one a context menu will list them
  • Alt + End navigates down the inheritance hierarchy and behaves like Alt + Home

Ctrl + U and Ctrl + Alt + B respectively is the equivalent for the ReSharper 2.x / IDEA scheme.

叫嚣ゝ 2024-12-12 12:17:10

我认为仅靠 resharper 是不可能做到这一点的。就 resharper 而言,您的单元测试只是 UserService 的另一种用法。

此外,所有不同的单元测试框架都有不同的指定,因此很难知道。例如,执行 bdd 会产生几乎与正在测试的类完全无关的测试类名称。

您也许可以编写一个扩展来执行此操作,也许使用属性或其他东西?没有把握。

i don't think this is going to be possible with just resharper. as far as resharper is concerned, your unit test is just another usage of UserService.

also, all of the different unit testing frameworks specify things differently, so it'd be tough to know. for instance, doing bdd would yield test class names almost entirely unrelated to the class(es) being tested.

you might be able to write an extension to do this, maybe using attributes or something? not sure.

七分※倦醒 2024-12-12 12:17:10

您可以使用 ReSharper 扩展 TestCop

该插件设计用于与 mstest 和 mstest 一起使用。 nunit 但应该与任何其他需要分配测试属性的单元测试框架一起使用。

You can use the ReSharper Extension TestCop

This plugin is designed for use with mstest & nunit but should work with any other unittest framework that requires you to assign a test Attribute.

遇到 2024-12-12 12:17:10

使用 ReSharper 和 NUnit,要从测试跳转到主题,您可以使用 TestFixture 属性的 TestOf 属性。只需按住 Ctrl 键并单击测试文件中的 MyClass

[TestFixture(TestOf = typeof(MyClass))]
public class MyClassTest

要从主题跳转到测试,请使用 ReSharper 查找用法 命令。

With ReSharper and NUnit, to jump from test to subject, you can use the TestOf property of the TestFixture attribute. Just Ctrl + Click on MyClass in the test file:

[TestFixture(TestOf = typeof(MyClass))]
public class MyClassTest

To jump from subject to test, use the ReSharper Find usage command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文