I want specs2 to do something in common before running the test.

Asked 2 months ago, Updated 2 months ago, 5 views

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
    }
  }
}

scala playframework

2022-09-30 11:10

1 Answers

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


2022-09-30 11:10

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.