New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@Injectable instance gets replaced after first test in testclass #405
Comments
In CrawlerControllerTest.java, there are no static @Injectable fields; "MockUp mocked" is static, but that is fine if the mock-up is to be reused between tests. I think the tests should use a real "RunningRequests" object, though, since it's "just" a map:
With this change, three of the tests continue to pass and two fail (with a "404" result instead of the expected "200"). I didn't examine the tests to see why, but they can probably be changed so they pass with the real |
Why MockUp mocked has to be static? BTW having mocked static works only with JDK 1.8.66, not with 1.8.121: runningRequests is null after the first test. There are no data in runningRequests, that's causing the 404 and that's one of the reasons I mocked it. The other reason is that I need CrawlerController to work no matter the RunningRequest implementation. RunningRequestsImpl must be tested by a test unit of its own. |
There is no need for any
|
And here is a better version for
|
Thanks for the advice about the test implementation and for providing a better implementation! :) |
I have a test class using spring-test to test a spring-mvc controller. The controller has a @Autowired field, filled by an @Injectable field in the test class. The injectable field has been initialized using a MockUp instance to mock some methods. The first test executed from the class works, when the second test is launched the injectable instance has changed and it's not using my mock anymore, that results in a NullPointerException in the controller class.
I've been able to run the tests by some hack (by making the injectable field static) with JDK 1.8 update 66 on Windows 2008.
I included a zip of the project to help reproduce the problem.
test.zip
The text was updated successfully, but these errors were encountered: