voddan
12/03/2017, 3:08 PMon("1122") {
val input = "1122"
val result = taskA(input)
it("should produce 3") {
assertEquals(3, result)
}
}
As you see, there are unfortunate repetitions of the input value and the assert value if I want to use them in the section names. How do you tackle that?voddan
12/03/2017, 3:11 PMon("1122") {
val input = "1122"
val result = taskA(input)
val expect = 3
it("should produce $expect") {
assertEquals(expect, result)
}
}
But I can't do that for the input value, can I?twbarber
12/03/2017, 3:34 PMon(...)
is a description of what the specification is confirming. "1122" is a bit less verbose than what a description should be (maybe not with context, and just my opinion, take that with a grain of salt).
Technically, you could extract that 1122
to a variable before the on
block like this:
val firstTestvalue = "1122"
on(firstTestvalue) {
val result = taskA(firstTestvalue)
...
However, I don't think that does anything for readability of the test. the way you have it now looks better IMO.twbarber
12/03/2017, 3:36 PMval input = "1122"
and call val result = taskA("1122")
without losing any clarity.voddan
12/03/2017, 6:49 PMon{}
sections:
given{
val input = ...
on("such $input" ) {...}
val input = ... // name clash or an ugly inconsistency :disappointed:
on("such $input" ) {...}
twbarber
12/03/2017, 6:56 PMon("1122") {
val result = taskA("1122")
it("should produce 3") {
assertEquals(3, result)
}
}
twbarber
12/03/2017, 6:57 PMgiven("...") {
it("should return 3 when the input is 1122") {
assertEquals(3, taskA("1122"))
}
it("should return X when the input is Y") {
assertEquals(X, taskA("Y"))
}
...
}
voddan
12/03/2017, 7:42 PMon{}
??? That's very cool, will try it! Thanks!