而我那些過於誰在黃瓜選擇scalatest
之一,黃瓜是太多,我(ME)寫的特徵文件,然後回到scala/java文件並相應地改變。保持兩個文件。我其實玩過cucumber java
,scala cucumber
可能會更流利。無論如何,我對所有的單元測試,組件測試和流量測試都非常喜歡scalatest。
如果像你這樣的,如果屬性是多個場景常見的,你會不會發生變異裏面的場景,然後定義爲公共財產將被罰款,如下圖所示。
class E2E extends FeatureSpec with GivenWhenThen {
feature("Features of mus client") {
Given("http config")
val config: Properties = new Properties(){{
put("method", "POST") //you are doing POST in both case by the way
put("encoding", "UTF-8")
put("uri", "http://localhost:9083/musClient")
}}
scenario("GET message with mus client") {
When("I make a request to f2e")
val response = HttpClientTest.request(config, createJSON(READ))
Then("The message it´s returned successfully")
assert(response != null)
}
scenario("POST message with mus client") {
When("I make a request to f2e")
val response = HttpClientTest.request(config, createJSON(CREATE))
Then("The message it´s returned successfully")
assert(response != null)
}
}
}
但是,你也可能要使用property based testing關於改變,基於屬性的檢查是非常流暢,可讀性於spock framework的唯一部分。
基於屬性的scalatest檢查看起來像下面我正在測試兩個不同的輸入參數。 (您neeed import org.scalatest.prop.TableDrivenPropertyChecks._
)
class TestE2E extends FeatureSpec with GivenWhenThen {
val requestResponse =
Table(
("request", "response"),
( "GET", "GET-something"),
("POST", "POST-something")
)
feature("testMe") {
forAll (requestResponse) { (givenRequestFromTable: String, expectedResponseFromTable: String) =>
scenario("for input " + givenRequestFromTable) {
When("input is " + givenRequestFromTable)
val output = testMe(input = givenRequestFromTable)
Then("responseFromTable has something appended to it")
assert(output == expectedResponseFromTable)
}
}
}
def testMe(input: String) : String = {
input + "-something"
}
}
會有基於兩個性能給出兩種方案,
和爲貴,測試將與財產的東西如下爲主,希望有沒有編譯錯誤: )
import org.scalatest.prop.TableDrivenPropertyChecks._
import org.scalatest.prop.Tables.Table
import org.scalatest.{FeatureSpec, GivenWhenThen}
class PaulWritesSpecs extends FeatureSpec with GivenWhenThen {
val requestResponse =
Table(
("httpMethod", "requestType"),
("GET", READ),
("POST", CREATE))
feature("Features of mus client") {
forAll(requestResponse) { (httpMethod: String, requestType: String) => {
scenario(s"$httpMethod message with mus client") {
Given("http config")
val config: Properties = new Properties() {{
put("method", httpMethod)
put("encoding", "UTF-8")
put("uri", "http://localhost:9083/musClient")
}}
When("I make a request to f2e")
val response = HttpClientTest.request(config, createJSON(requestType))
Then("The message it´s returned successfully")
assert(response != null)
}
}
}
}
}