Marko Zadravec
Marko Zadravec

Reputation: 8730

Scout Eclipse ScoutServerTestRunner on client tests

now I run on new problems with scout testing.

I have Client fragment project for testing and I would like to test some templates I created.

My problem is that this templates contains some SmartFields and I would like to test them. For this I probably need ScoutServerTestRunner, so the server is up and running.

But If I try to add it I get error :

@RunWith(ScoutServerTestRunner.class)
@ServerTest()

I get error :

ServerTest cannot be resolved to a type

, all of my assert imports are deleted and I get error on my package line suggesting me Configure build path.

My guess is that this can't be done because it is client fragment and it can't connect to server. But how then test smartFields ?

Upvotes: 0

Views: 215

Answers (1)

Jmini
Jmini

Reputation: 9497

From your question I guess that there is some misunderstanding...


ScoutServerTestRunner and @ServerTest is something similar to ClientServerTestRunner and @ClientTest but for the server. You will need it for tests testing the server.

The classes are located in the org.eclipse.scout.rt.testing.server bundle.


If in a client test you need a server you have two possibilities:

A/ Start a server

You can start a server

Scout tests with a server

This will probably not be the normal server (the one like in production) because you want to control the database or some external services. Authentication might also be slightly different (in order to control it and to have something compatible with your tests)

For the integration in your maven build, the maven-cargo plugin can be used to start your server before executing the client test suite.

B/ Mock the server services

Each of the services call that creates a ProxyService calling the server, can be replaced by mock (client only).

Scout tests with mocked server services]

This is the preferred way for unit test, because you do not rely on a deployed server. You can also define for each test what the server answer will be. This solutions requires probably initially more work, but in my opinion it worth it.

To register an alternative service, you can use:

TestingUtility.registerServices(
     <activator instance>, 
     <priority>, 
     <service instances>
);

The service with the higher priority will win.

In each test, do not forget to un-register the alternative services you have registered.


SmartFields are using CodeTypes or LookupCalls. In case of a LookupCall, the LookupCall is probably calling the server through a LookupService. In case of a CodeType, the SmartField is internally using the CodeLookupCall class relying on a ICodeService.

In both cases, if you want to run your test without a server, you need to ensure that the client uses alternative implementations of the required services that do requires a server.

Upvotes: 2

Related Questions