spring ベースのシステムを構築する予定で、Groovy ベースの BDD フレームワークを使用したいと考えています。システムも OSGi ベースです。
春からのSTS日食にも適合する優れたBDDフレームワークの提案はありますか?
そのような環境でモックをどのように使用しますか? OSGi は、多くの外部依存関係をモックする必要があります。
ありがとう!
Spock テスト フレームワークは、Groovy に基づく強力な BDD に着想を得たテスト フレームワークです。それは多くの機能を備えており、まさにあなたが探しているものかもしれません.
低いバージョン番号 (現在のバージョンは 0.7) に惑わされないでください。長い間、安定しており、本番環境で使用できるようになっています。Java、Groovy、Griffon、Grails のプロジェクトをテストするために少なくとも 2 年間は使用してきましたが、元に戻すことは考えていません...
これは JUnit の上に構築されており、JUnit が実行されるすべての環境 (少なくとも私が認識している環境) で実行されます。通常の JUnit テストとして、Eclipse および IntelliJ IDEA 内から実行されます。
非常に単純な例 (注: などの後のコメントexpect:
はwhere:
オプションです):
import spock.lang.Specification
class SpockExampleSpecification extends Specification {
def "a String should return correct length"() {
expect: "correct length"
myString.length() == length
where: "different strings have different lengths"
myString | length
"hello" | 5
"abc" | 3
"" | 0
}
def """show a string mock that could be injected into a class;
using groovy metaClass, spring injection or any other means"""() {
given: "a mock for char sequence, injected into DoubleLength"
def mock = Mock(CharSequence)
def dsl = new DoubleLength(myString: mock)
when: "accessing lengths from this mock"
def doubleLength = dsl.length()
then: """mock value should be used and we should
get the expected interactions with the mock"""
1 * mock.length() >> 1234
doubleLength == 2468
}
}
class DoubleLength {
def myString
def length() {
2 * myString.length()
}
}