You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And this is the test method I wrote for the above method:
@Test@DirtiesContextpublicvoidtestCheckDetach() {
// Case will fail in unit testing.LongnewId = courseRepository.checkPersistence();
Coursecourse = courseRepository.findById(newId);
assertEquals("HAPPY PYTHON", course.getName());
}
The above test case will not pass as the target course entity is still updated even after it was detached.
However, if running the application directly with the below method defined in the run method as follows:
This will correctly reflect what the checkDetach() specifies, which will successfully detach the target course entity and will not update the associated entry in the h2 database.
So I am quite confused and wondering what I missed to create a correct unit test case for the checkDetach method and I would really appreciate if you could provide some suggestions on that.
The text was updated successfully, but these errors were encountered:
It turns out that I was using an incorrect method when writing my test method, which should use checkDetach instead of checkPersistence. I guess that was simply caused by a copypaste and really sorry for open it as an issue here. Now everything is working for me, so I will close this issue.
Hello Ranga,
I am learning the course associated with this repo and I am at the Step#12 of Chapter#5, which is to play with the entitymanager.
This is the target method in my CourseRepository class:
And this is the test method I wrote for the above method:
The above test case will not pass as the target course entity is still updated even after it was detached.
However, if running the application directly with the below method defined in the run method as follows:
This will correctly reflect what the checkDetach() specifies, which will successfully detach the target course entity and will not update the associated entry in the h2 database.
So I am quite confused and wondering what I missed to create a correct unit test case for the checkDetach method and I would really appreciate if you could provide some suggestions on that.
The text was updated successfully, but these errors were encountered: