0

ビルド システムとして ant を使用して ScalaTest を試しています。サンプルコードを使用しようとしています:

package se.uu.molmed.SandBoxScalaTest

import org.scalatest.FlatSpec
import org.scalatest.Tag

object SlowTest extends Tag("com.mycompany.tags.SlowTest")
object DbTest extends Tag("com.mycompany.tags.DbTest")

class TestingTags extends FlatSpec {

  "The Scala language" must "add correctly" taggedAs(SlowTest) in {
      val sum = 1 + 1
      assert(sum === 2)
    }

  it must "subtract correctly" taggedAs(SlowTest, DbTest) in {
    val diff = 4 - 1
    assert(diff === 3)
  }
}

そして、次のantターゲットを使用して実行しようとしています:

<!-- Run the integration tests -->
<target name="slow.tests" depends="build">
    <taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestAntTask">
        <classpath refid="build.classpath" />
    </taskdef>

    <scalatest parallel="true">
        <tagstoinclude>
            SlowTests   
        </tagstoinclude>
        <tagstoexclude>
            DbTest
        </tagstoexclude>

        <reporter type="stdout" />
        <reporter type="file" filename="${build.dir}/test.out" />

        <suite classname="se.uu.molmed.SandBoxScalaTest.TestingTags" />
    </scalatest>
</target>

問題なくコンパイルされ、スイートが実行されますが、テストは含まれていません。上記のコードの 2 つのテストのうち最初のテストを実行することを期待しています。出力は次のようになります。

slow.tests:
[scalatest] Run starting. Expected test count is: 0
[scalatest] TestingTags:
[scalatest] The Scala language
[scalatest] Run completed in 153 milliseconds.
[scalatest] Total number of tests run: 0
[scalatest] Suites: completed 1, aborted 0
[scalatest] Tests: succeeded 0, failed 0, ignored 0, pending 0, canceled 0
[scalatest] All tests passed.

これがなぜなのかについてのアイデアはありますか?どんな助けでも大歓迎です。

4

1 に答える 1

1

問題は、タグの名前が Tag コンストラクターに渡される文字列であることです。あなたの例では、名前は「com.mycompany.tags.SlowTest」と「com.mycompany.tags.DbTest」です。Ant タスクの tagsToInclude 要素と tagsToExclude 要素でこれらの文字列を使用すると、次のように修正されます。

<scalatest parallel="true">
    <tagstoinclude>
        com.mycompany.tags.SlowTest   
    </tagstoinclude>
    <tagstoexclude>
        com.mycompany.tags.DbTest
    </tagstoexclude>

    <reporter type="stdout" />
    <reporter type="file" filename="${build.dir}/test.out" />

    <suite classname="se.uu.molmed.SandBoxScalaTest.TestingTags" />
</scalatest>

テストをメソッドとして記述する場合や、クラス内のすべてのテストに一度にタグを付けたい場合の両方で、場合によってはアノテーションをタグ付けに使用できるようにするため、このややエラーが発生しやすい設計は残念ながら強制されています。たとえば、(ScalaTest 2.0 では) 次のように、クラスの @Ignore アノテーションを使用して、クラス内のすべてのテストを無視するようにマークできます。

org.scalatest._ をインポート

@Ignore class MySpec extends FlatSpec { // ここにあるすべてのテストは無視されます }

ただし、org.scalatest.Ignore だけでなく、任意のタグでこれを行うことができます。したがって、Tag クラスに渡す文字列は、そのタグの姉妹アノテーションの完全修飾名になることを意図しています。このデザインの詳細は次のとおりです。

http://www.artima.com/docs-scalatest-2.0.M3/#org.scalatest.Tag

于 2012-08-16T21:11:38.497 に答える