2012-01-04 4 views

答えて

0

テストプロジェクトが通常のクラスライブラリに過ぎないことを考慮すれば、テストメソッドのドキュメントをXML commentsでデコレートすることができます。 NUnitのようなテストフレームワークを使用している場合は、test case factory (http://www.nunit.org/index.php?p=factory&r=2.5)を使用してメソッドに入力パラメータを提供し、xmlコメントでテストの入力データを記述できるようにすることができます。また

は、この質問はaswellしばらくの間、私と一緒にされてい GhostDoc

+0

私はすでにGhostDocを使用しています。ドキュメントユニットテスト。ドキュメントには、ドキュメントのプレーンテキストのリストが含まれている必要があります。http://testdoc.codeplex.com/ – slamballx

+1

のようなものです。XMLドキュメントの出力を変更することができます。あなたのメトーds、それは限界です。テストを書くためのより記述的な方法をお探しなら、BDDを見てください。 StoryQは優れたフレームワーク(http://storyq.codeplex.com/)です。ここで簡単なサンプルを見つけることができます:http://www.codeproject.com/KB/testing/bddintro.aspx –

+0

ありがとう@ george2giga私は検討しますBDDを使用します。 – slamballx

1

ユニットテストはコードの文書であると考えられます。したがって、ドキュメントを文書化することは、要件として少し奇妙に見えます。

これは、単体テストは通常​​のコードなので、通常のコードを文書化するために使用しているのと同じツールを使用することができます。コード内にXMLコメントがあり、ドキュメントを生成するのにSandcastleのようなものは、心に浮かぶツールの1つです。

+0

は今、私は私の目的は私の同僚にテストケースのリストを与えることですhttp://testdoc.codeplex.com/ – slamballx

+0

で探していますユニットテストをしていないので、 "プレーンテキスト"で書かれています。これは単体テストの世界に近づくのに適した方法だと思います。 – slamballx

1

を見てみましょう。私は既存のBDDフレームワークを認識していますが、少なくとも私が試したものはあまりにも多くのオーバーヘッドがあるように感じます。単体テストを書くときは、Gherkinを使います。 @Darin Dimitrovのように、単体テストはコードのドキュメントとして機能することができますが、テストの記述がテストの正確な意図を理解するのに十分でない可能性があるため、テストケースは人間が読みやすく/アクセスできません。以下のユニット・テストを考えてみましょう:

[Test(Description: "Scenario: Attempting to square root a negative number")] 
public void AttemptingToSquareRootANegativeNumber() { 

    // Given a calculator 
    // Calculator calculator = new Calculator(); 

    // When square-rooting a negative number 
    // Action squarerootAction =() => calculator.SquareRoot(-1) 

    // Then an Exception should be thrown. 
    Assert.That(squarerootAction) 
     .Throws<ArgumentException>("you cannot square root a negative number"); 

} 

このユニットテストが自動的に単純なテキスト/ htmlファイルに変えることができれば、それは超いいだろう、のようなもの:

Feature: "Square-rooting" two numbers 
Scenario: Attempting to square root a negative number 
    Given a calculator 
    When square-rooting a negative number 
    Then an Exception should be thrown. 

はっきり読めるとに簡単に厥をわかる。このように単体テストから人が読めるテストケースを生成することで、開発者は単体テストを人間が読めるストーリー(例えば、StoryQのようなspecflow)から単体テストを生成しようとするような方法で記述することができます。そのようなdoumentation-generating library(すでに存在しない場合)を作成することは非常に難しいことではありません。たぶんxBehaveが出発点になる可能性がありますか?

StoryQのドキュメントを見ると、"Retrofit"単体テストが可能なように見えるので、StoryQストーリーは既存の単体テストから生成できますが、改造には多くの作業が必要です。

0

私はパーティーに数年遅れましたが、私はちょうどhttp://blog.aabech.no/archive/generating-documentation-from-nunit-tests/でこれについての投稿を書いています。

上記がオフラインになった場合、その要点はデフォルトでNUnit ConsoleランナーがXMLファイルを出力することです。ツールに--result = SPEC引数を1つ以上追加することで、それを無効にすることができます。仕様はXSLT変換を指すことができ、代わりにHTML出力を取得します。私はXSLTもプレーンテキストを行うことができると思うので、それはあなた次第です。 :)

例を以下に示します。
nunit3-console.exe My.Tests.dll --result: "TestSummary.htm; transform = TestSummary。XSLT」

とシンプルなHTML変換:

<?xml version="1.0" encoding="iso-8859-1"?> 
<xsl:stylesheet 
    version="1.0" 
    exclude-result-prefixes="msxsl" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
    > 
    <xsl:output method="html" indent="yes"/> 

    <xsl:template match="@* | node()"> 
    <html> 
     <head> 
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"/> 
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"/> 
     <style type="text/css"> 
      .Passed { color: green; } 
      .Inconclusive { color: #BBAA00; } 
      .Failed { color: red; } 

      ul { 
      margin-left: 0px; 
      list-style-type: none; 
      padding-left: 0; 
      } 

      ul ul { 
      margin-left: 15px; 
      } 

      .counts { 
      font-size: .7em; 
      color: gray; 
      } 
     </style> 

     </head> 
     <body> 
     <div class="container"> 
      <xsl:apply-templates select="/test-run/test-suite"/> 
     </div> 
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous">// Force closing tag</script> 
     <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js">// Force closing tag</script> 
     <script type="text/javascript"> 
      $("td").each(function(i, e) { 
      $(e).text($(e).text().replace(/_/g, " ")); 
      }); 
     </script> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template match="/test-run/test-suite"> 
    <h1> 
     <xsl:value-of select="./test-run/@name"/> 
    </h1> 
    <table class="table table-striped"> 
     <xsl:apply-templates select="./test-suite"/> 
    </table> 
    </xsl:template> 

    <xsl:template match="test-suite"> 
    <tr> 
     <td> 
     <xsl:attribute name="class"> 
      <xsl:choose> 
      <xsl:when test="./@failed > 0">Failed</xsl:when> 
      <xsl:when test="./@inconclusive > 0">Inconclusive</xsl:when> 
      <xsl:otherwise>Passed</xsl:otherwise> 
      </xsl:choose> 
     </xsl:attribute> 
     <xsl:attribute name="style"> 
      padding-left: <xsl:value-of select="count(ancestor::test-suite)*15"/>px; 
     </xsl:attribute> 
     <xsl:value-of select="./@name"/> 
     </td> 
     <td class="counts"> 
     <xsl:value-of select="./@passed"/> passed, 
     <xsl:value-of select="./@inconclusive"/> inconclusive, 
     <xsl:value-of select="./@failed"/> failed 
     </td> 
    </tr> 
    <xsl:for-each select="./test-suite"> 
     <xsl:apply-templates select="."/> 
    </xsl:for-each> 
    <xsl:for-each select="./test-case"> 
     <xsl:apply-templates select="."/> 
    </xsl:for-each> 
    </xsl:template> 

    <xsl:template match="test-case"> 
    <tr> 
     <td colspan="2"> 
     <xsl:attribute name="style"> 
      padding-left: <xsl:value-of select="count(ancestor::test-suite)*15"/>px; 
     </xsl:attribute> 
     <xsl:attribute name="class"> 
      <xsl:value-of select="./@result"/> 
     </xsl:attribute> 
     <xsl:value-of select="./@name"/> 
     </td> 
    </tr> 

    </xsl:template> 
</xsl:stylesheet> 
関連する問題