I'd like to create a test case for the APIs that are supposed to log in, but I need to log in as a preliminary step.
What should I do if I need to log in before running the test and run the test case using the return value (session ID)?
I'd like to log in only once.
If you continue, you will be told that you cannot instantiate it with Could not create an instance of HogeSpec
.
class HogeSpec extensions Specification {
// I want to use this userSessionId for each test case
val userSessionId = BaseSpec.beforeAuth()
"Testing hogeAPI" should {
"Status 200 returned" in {
// something
// I want to test the API using userSessionId
}
}
"Testing fugaAPI" should {
"Status 200 returned" in {
// something
// I want to test the API using userSessionId
}
}
}
Self-resolved.
Delay evaluation with lazy
was used to avoid errors.
UserSessionId can now be used around.
You did not need to use a special BeforeExample
.
-val userSessionId=BaseSpec.beforeAuth()
+ lazy val userSessionId = BaseSpec.beforeAuth()
This answer was helpful, so I will share it with you.
https://stackoverflow.com/questions/21830495/specs2-could-not-create-an-instance
© 2023 OneMinuteCode. All rights reserved.