I want a unit test class, Class A , but it has a dependency on another class that uses the user session method. The method I want to test does not include user session . Can I create a helper method in Class A that replicates the behavior of the Class B method that I need?
I know this is not clear, let them dig out the code to get a clear understanding ....
public void testDetails() throws Exception {
Now getDetailsSize() get size information from the database. Class B has this method, but I cannot create a Class B object and test this method, because Class B receives session information from the user, and I can set the session information from the JUnit class.
I created the saveDetailsHelper method, which replicates the behavior of the Class B - saveDetails() method Class B - saveDetails() and calls it in the testDetails() method, as shown above.
My question is:
- Can we have helper methods in the
junit class ? - What is best suited to solve this problem?
source share