MSTEST/VSTS 反射工具

发布于 2024-07-14 18:54:32 字数 211 浏览 6 评论 0原文

有谁知道有一种工具可以输出解决方案中具有 [TestMethod] 属性的所有方法的列表?

我们想要完成的是与客户一起根据要求审查我们的单元测试(名称,而不是通过/失败状态)。 我们正在使用 VSTS 2008 和 Scrum for Team Systems,所以我不确定这是否是内置的东西,或者它是否是我只需要为了我们的目的而组合在一起的工具。 任何帮助都会很棒。 谢谢。

Does anyone know of a tool that will spit out a list of all methods with the [TestMethod] attribute within a solution?

What we're trying to accomplish is a review, with the customer, of our Unit Tests (names, not pass/fail status) against the Requirements. We are using VSTS 2008 and Scrum for Team Systems, so I wasn't sure if this was something that was built in somewhere, or if it's a tool I just need to toss together for our purposes. Any help would be great. Thanks.

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

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

发布评论

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

评论(1

凡间太子 2024-07-21 18:54:32

VS本质上是通过生成TRX文件来总结测试运行的结果来免费提供这种能力的。 有多种不同的方法可以运行项目中的所有测试,但选择一种方法即可,mstest 将使用 [TestMethod] 属性运行每个方法,并在结果文件中生成 UnitTestResult。

您所要求的本质上是测试运行完成后“测试结果”窗口向您显示的内容。 如果您正在寻找 VS 外部的内容,您始终可以针对测试结果 (.trx) 文件运行简单的 XSLT 转换,从而为您提供自定义摘要。 这是一个非常粗略的示例,它证明了这个概念,生成一个 HTML 文档,其中包含一个无序列表,其中每个单元测试都有一个列表项(测试名称和结果):

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:vs="http://microsoft.com/schemas/VisualStudio/TeamTest/2006">

    <xsl:template match="/">
        <html>
            <head>
                <style type="text/css">

                    body { font-family: verdana; font-size: 12px; }

                    .pass { color: green; }
                    .nopass { color: red; }

                    h1 { font-size: 13px; margin: 3px; }

                    ul { margin: 3px 20px 3px 40px; }
                </style>
            </head>
            <body>

                <h1>Test Results</h1>
                <ul>

            <xsl:apply-templates select="//vs:Results//vs:UnitTestResult" />

                </ul>
            </body>
        </html>

    </xsl:template>
    <xsl:template match="vs:UnitTestResult" >
        <li>
            <xsl:value-of select="@testName" />
             

            <xsl:variable name="Result">
                <xsl:choose>
                    <xsl:when test="@outcome='Passed'">pass</xsl:when>
                    <xsl:otherwise>nopass</xsl:otherwise>
                </xsl:choose>
            </xsl:variable>

            <b class="{$Result}">
                <xsl:value-of select="@outcome" />
            </b>
        </li>

    </xsl:template>
</xsl:stylesheet>

VS essentially offers this ability for free by generating the TRX file to summarize the results of a test run. There are a number of different ways to run all tests in a project but pick one and off mstest will go running each method with the [TestMethod] attribute and producing a UnitTestResult in the results file.

What you're asking for is essentially what the Test Results window shows you after a completed Test Run. If you're looking for something external to VS, you could always run a simple XSLT transform against the Test Results (.trx) file giving you a customized summary. Here's a very rough sample which proofs the concept, generating an HTML document containing an unordered list with a list item (test name and result) for each unit test:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:vs="http://microsoft.com/schemas/VisualStudio/TeamTest/2006">

    <xsl:template match="/">
        <html>
            <head>
                <style type="text/css">

                    body { font-family: verdana; font-size: 12px; }

                    .pass { color: green; }
                    .nopass { color: red; }

                    h1 { font-size: 13px; margin: 3px; }

                    ul { margin: 3px 20px 3px 40px; }
                </style>
            </head>
            <body>

                <h1>Test Results</h1>
                <ul>

            <xsl:apply-templates select="//vs:Results//vs:UnitTestResult" />

                </ul>
            </body>
        </html>

    </xsl:template>
    <xsl:template match="vs:UnitTestResult" >
        <li>
            <xsl:value-of select="@testName" />
             

            <xsl:variable name="Result">
                <xsl:choose>
                    <xsl:when test="@outcome='Passed'">pass</xsl:when>
                    <xsl:otherwise>nopass</xsl:otherwise>
                </xsl:choose>
            </xsl:variable>

            <b class="{$Result}">
                <xsl:value-of select="@outcome" />
            </b>
        </li>

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