Nigel Thomas
Nigel Thomas

Reputation: 1929

How to create a user session while running Junit test case

I have written some test cases in Junit. Now while running these test cases I am getting an error because the values needed for some of the attributes are to be provided from a user session , like the user name. So how is it possible to create a user session while running the Junit test case and provide the session values for these attributes. I have to enter these attributes into an Oracle database. Thanks, Nigel.

Upvotes: 1

Views: 3177

Answers (2)

Nigel Thomas
Nigel Thomas

Reputation: 1929

Create a properties file where you define the username and password. Write a custom method to getUserSessionObject using the username and password(if needed because you can select the user details from the database using the username itself) from the properties file. Set the userSessionVariables from the getUserSessionObject. Call this function whenever the commit is called.

Upvotes: 0

MattR
MattR

Reputation: 7048

There are some mock implementations for HTTP testing - for example Spring has org.springframework.mock package including classes like MockHttpSession.

Using mocks you can create a test instance and pre-populate it with test values so to your code it looks like a real session.

Upvotes: 4

Related Questions