|[neon] Problems with server unit test -> @BeforeClass called too late [message #1755123]
||Tue, 28 February 2017 09:36
| Urs Beeli
Registered: October 2012
Location: Bern, Switzerland
I've been migrating some of my server unit tests. However, I have stumbled across a situation I cannot seem to solve.|
My setup is as follows:
In my productive code, I have a MyServerPlatformListener which implements IPlatformListener. In its stateChanged() method, it calls some other classes that I need to mock for my tests.
In my unit test (which is annotated with @RunWith(ServerTestRunner.class) I have both a static setup method annotated with @BeforeClass and a normal setup method annotated with @Before. The static setup method mocks those classes used by the PlatformListener.
However, it seems that the PlatformTestRunner and/or ServerTestRunner are setup in a way which causes the Platform to be started before the @BeforeClass method is called. This means that my mocked bean is not yet available which causes the PlatformListener to throw an exception which then causes the Platform to be set to PlatformInvalid which aborts the test before any of the setup methods are called.
I have tried extending MyServerPlatformListener with a TestMyPLatformListener which has a @Replace annotation, in it I have overwritten the stateChanged method to either keep the original from being called or to setup the mocks before passing the call to the original. However, it seems that this platform listener is not even picked up by the Bean Manager.
So, in effect, I am unable to mock the classes referenced by the PlatformListeners for my tests.
Is this a bug in the test setup nobody has stumbled across yet? Or am I doing something wrong? How can I get around this issue?
Powered by FUDForum
. Page generated in 0.01756 seconds