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
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
582 PHP ssh2_scp_send fails to send files as intended
620 Uncaught (inpromise) Error on Electron: An object could not be cloned
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.