Find out whattime the next trains for my destination station leave
Narrative:
In order to plan my trips more effectively
As a commuter
I want to know the next trains going to my destinations
Scenario: Find the optimal itinerary between stations on the name line
Given Western line trains from Emu Plains leave Parramatta for Town Hall at 7:58, 8:00, 8:02,
8:11, 8:14, 0:21
When I want to travel from Parramatta to Town Hall at 8:00
Then I should be told about the trans at: 8:02, 8:11, 8:14
BDDシナリオ
出典:BDD in Action
46.
class ReservationServiceSpec extendsAnyFreeSpec
with Matchers
with GivenWhenThen
with ReservationMatchers {
"ReservationService" - {
"reserveメソッド" - {
"予約の追加" - {
"現在時刻より後ろの有効な予約時間を予約" in {
Given("テスト⽤に作成したReservationServiceを使⽤")
val service = ReservationService.createForTest()
When("運⽤時間内の時間")
val dt = "2024-01-15T10:00:00+JST"
Then("テスト対象時刻で実⾏コンテキストを⽤意")
given ExecutionContext = ExecutionContext.createWithCurrentDateTime(dt)
And("現在時刻より後ろの有効な予約時間で予約")
ReservationServiceSpec.sbt (1/2) 再掲 第31回 設計/実装(2)
47.
val rid =ResourceId("id1234")
val uid = UserId("user789")
val start = LocalDateTime.of(2024, 1, 15, 11, 00)
val end = LocalDateTime.of(2024, 1, 15, 12, 00)
val interval = Interval.openUpper(start, end)
val cmd = ReserveCommand(rid, uid, interval)
service.reserve(cmd) should successReserve(cmd)
}
}
}
}
}
ReservationServiceSpec.sbt (2/2) 再掲 第31回 設計/実装(2)
48.
sbt:reservation> test
[info] compiling2 Scala sources to
/Users/asami/src/Project2023/ofad/domain/target/scala-3.1.1/test-classes ...
[info] done compiling
[info] ReservationServiceSpec:
[info] ReservationService
[info] reserveメソッド
[info] 予約の追加
[info] - 現在時刻より後ろの有効な予約時間を予約
[info] + Given テスト⽤に作成したReservationServiceを使⽤
[info] + When 運⽤時間内の時間
[info] + Then テスト対象時刻で実⾏コンテキストを⽤意
[info] + And 現在時刻より後ろの有効な予約時間で予約
[info] Run completed in 270 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 1 s, completed 2024/01/16 16:00:27
テストを実⾏ 再掲 第31回 設計/実装(2)