그리고 오이에 걸쳐 scalatest
를 선택 너무 사람들의 일이야, 오이는 기능 파일을 작성하는 나 (ME) 너무 많이 한 후, scala/java 파일로 돌아와서 그에 맞게 변경하십시오. 두 개의 파일을 유지 보수하십시오. 실제로 cucumber java
을 연주 했으니 scala cucumber
이 더 유창 할 것입니다. 어쨌든, 지금까지 모든 유닛 테스트, 컴포넌트 테스트 및 플로우 테스트에 대해 스칼라 테를 좋아합니다.
속성이 여러 시나리오에서 공통적 인 경우 내부 시나리오를 변경하지 않으면 공통 속성으로 정의하는 것이 좋을 것입니다.
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)
}
}
}
그러나,는 또한 재산 기반 검사 spock framework 매우 유창하게 읽을 수 있었다 만 변경 부분에 대한 property based testing을 사용할 수 있습니다.
scalatest의 속성 기반 검사는 다음과 같이 두 개의 다른 입력 매개 변수를 테스트합니다. (당신이 import org.scalatest.prop.TableDrivenPropertyChecks._
을 neeed)
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)
}
}
}
}
}