Scout Eclipse ScoutServerTestRunner客户端测试 [英] Scout Eclipse ScoutServerTestRunner on client tests

查看:217
本文介绍了Scout Eclipse ScoutServerTestRunner客户端测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我运行侦察测试的新问题。

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.

我的问题是这个模板包含一些SmartFields,我想测试他们。为此,我可能需要 ScoutServerTestRunner ,因此服务器已启动并正在运行。

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()

我得到错误:

ServerTest cannot be resolved to a type

类型,我所有的 assert 导入被删除,我在我的行显示错误行建议配置构建路径

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

我的猜测是,这不能做,因为它是客户端片段,它不能连接到服务器。
但是如何测试smartFields?

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 ?

推荐答案

从您的问题我猜想有一些误解...

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

ScoutServerTestRunner @ServerTest 类似于 ClientServerTestRunner @ClientTest ,但是对于服务器。

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

这些类位于 org.eclipse.scout.rt.testing.server bundle。

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:

您可以启动服务器

可能不是正常的服务器(一个在生产中),因为你想控制数据库或一些外部服务。身份验证也可能稍有不同(为了控制它并且与测试兼容)

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)

对于maven构建中的集成,maven-cargo插件用于在执行客户端测试套件之前启动您的服务器。

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

的服务调用创建一个ProxyService调用服务器,可以替换为mock(仅客户端)。

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

这是单元测试的首选方法,因为你不依赖部署的服务器。您还可以为每个测试定义服​​务器的答案。

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正在使用CodeTypes或LookupCalls。在 LookupCall 的情况下, LookupCall 可能通过 LookupService 。在 CodeType 的情况下, SmartField 在内部使用 CodeLookupCall class依赖 ICodeService

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.

这篇关于Scout Eclipse ScoutServerTestRunner客户端测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆