从 IDE 中在远程服务器上运行 TestNG/JUnit 集成测试
在我的 IDE(Eclipse 或 NetBeans,没关系)中,我有一些 TestNG 测试类(但我的问题也指远程 JUnit 测试),它们是集成测试。这些测试需要集成服务器才能运行,它们不能在本地计算机上运行。他们需要集成服务器的完整环境 - 不仅仅是 JavaEE 容器相关的东西(=> 没有 Arquillian 也没有 JEEUnit)。
现在我希望能够从我的 IDE (Eclipse) 中运行这些测试 - 最好使用 TestNG 插件 - 但当我启动它们时,它们实际上应该在远程集成服务器上运行。
是否可以从我的 IDE 中在远程服务器上启动集成测试? 我喜欢在远程服务器上安装某种代理来等待测试请求并执行它们的想法。但正如我所说,如果它从 TestNG 插件内部运行,那就太好了。
我是否需要某种解决方法,例如 Ant 脚本(希望不需要)或一些 Maven 魔法?最佳实践是什么?
我知道我还可以为我的应用程序创建 Web 服务,然后我可以从本地单元测试中调用它们。但我想知道没有 Web 服务是否也有可能。
Inside my IDE (Eclipse or NetBeans, doesn't matter), i have some TestNG testclasses (But my question also refers to remote JUnit tests), which are Integration tests. These tests need an integration server to run, they cannot be run on a local machine. They need the complete environment of the integration server - not only JavaEE container related stuff (=> no Arquillian nor JEEUnit).
Now I want to be able to run these tests from within my IDE (Eclipse) - preferrably with the TestNG Plugin - but when I launch them they should actually be run on the remote integration server.
Is it possible to launch integration tests on a remote server from within my IDE?
I like the idea of having some kind of Agent on the remote Server which waits for test-requests and executes them. But as I said, it would be nice if this runs from inside the TestNG Plugin.
Do I need some kind of workaround, for example Ant scripts (hopefully not) or some Maven magic? What are the best practices?
I know I could also create Webservices for my application, then I can call them from local unit tests. But I'd like to know if there are also possibilities without Webservices.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如何完成此任务在很大程度上取决于您使用的集成服务器和 IDE,以及您的应用程序是什么。我假设您使用的是 Eclipse;我假设你正在使用 Jenkins,因为在我看来,它是最容易让它执行任务的你想要的。
其中大部分都可以开箱即用。然而,有一点需要一些额外的工作。
您需要执行以下操作:
现在是连接的稍微复杂的部分Eclipse 到詹金斯。不幸的是,我认为没有任何现有工具可以完全满足您的需求。好消息是,使用自定义脚本可以非常简单地实现。所有脚本要做的是:
$programFile
的变量中,http://:8080//buildwithparameters?TestingProgram=$programFile
您可以在 jenkins 文档。
完成这些步骤的脚本几乎可以是任何东西。鉴于您希望最终将其合并到您的 IDE 中,似乎最合乎逻辑的选择是 ant 脚本或 Eclipse 插件。两者都不会太复杂 - ant 脚本只会执行这些步骤,并且您可以将 ant 脚本导入到专门用于测试的 Eclipse 项目中 - 并且插件可以只添加一个菜单项,当在项目中运行时,该菜单项将执行该项目的上述步骤。
注意: 实际上有几种不同的方法可以使用 Jenkins 触发带有参数的构建。例如,您可以执行 POST 请求,使用 json 传递我链接到的 jenkins 文档中描述的参数,使用 Jenkins CLI 等。并非所有这些都可以使用文件参数,但您可以在非常相似的方式 - 作为自定义脚本中的一个步骤,您将在 Jenkins 上执行远程构建,并传递要用于测试的文件。例如,我给出的解释假设测试文件非常小;如果不是这种情况,您可能需要执行 POST 请求。如果您在使用一种方法时遇到问题,应该很容易切换到使用效果更好的其他方法。
How you will accomplish this depends a lot on what integration server and IDE you're using, and what you're application is. I'll assume you're using Eclipse; and I'll assume you're using Jenkins, since it will IMO be the easiest to get it to do what you want.
Most of this will work out of the box. However, there is a little bit that will require a some of additional work.
You'll want to do the following:
Now comes the slightly more complicated part of hooking up Eclipse to Jenkins. Unfortunately, I don't think there are any preexisting tools that will do exactly what you want. The good news is that it should be very simple to achieve with a custom script. All the script has to do is:
$programFile
http://<your-jenkins-server>:8080/<integrated-testing-job-name>/buildwithparameters?TestingProgram=$programFile
You can read up more on triggering Jenkins remote builds with parameters in the jenkins docs.
The script that accomplishes these steps can be pretty much anything. Given that you want to ultimately incorporate it into your IDE, it seems like the most logical choices would be an ant script or an Eclipse plugin. Neither would be too complicated - the ant script would just do those steps, and you could import the ant script into an Eclipse project specifically for doing testing - and a plugin could just add a menu item which, when run within a project, would execute the above steps for that project.
NOTE: There are actually several different ways to trigger a build with parameters using Jenkins. For example, you can do a POST request, use json to pass the parameter as described in the jenkins docs I linked to, use the Jenkins CLI, etc. Not all of them work with file parameters, but you would use them all in a very similar way - as a step in your custom script, you would execute a remote build on Jenkins, and pass the file you want to use to test with. For example, the explanation I gave assumes that the testing file is very small; if that's not the case, you might want to do a POST request instead. If you run into problems using one method, it should be pretty easy to switch it to use a different method that works better.
不幸的是,我没有现成的解决方案,但我想我可以给你一些提示,因为我花了一些时间思考这个问题。
我不了解 TestNG,但 JUnit 能够插入您自己的测试执行器。我确信 TestNG 具有适当的功能。所以,找到它并熟悉它。由于您可以控制测试的调用方式,因此您甚至可以执行其他操作,而不是调用测试用例的方法。例如,调用一些远程 API,使测试能够远程运行。
显然,它可以是使远程代理(根据您的建议)在远程计算机上运行测试的Web服务。很好,但我更喜欢无代理或半无代理的解决方案。我是什么意思?例如,如果您的远程计算机是 Unix,您可以执行 SSH 或 Telnet 连接并运行命令行。在这种情况下,您可以创建 mvn 或 ant 脚本,使用 ssh 复制到远程计算机,然后运行它。该脚本将运行您的测试。所以它几乎是无代理的。您只需要 java 安装和 SSH 支持。
如果远程计算机是 Windows,则可以使用 Telnet 或 WMI。因此,如果安全不是问题但您需要跨平台支持,请使用 Telnet。
如果您需要有关 SSH/Telnet 的更多帮助,请随时与我联系。
Unfortunately I do not have a ready solution but I think I can give you some tips since I spent some time thinking about this.
I do not know about TestNG but JUnit has ability to plugin your own test executor. I am sure that TestNG has appropriate functionality. So, find it and be familiar with it. Since you can control how your test is being invoked you can even do something else instead of invoking the test case's methods. For example call some remote API that will make the test to run remotely.
Obviously it can be web service that makes remote Agent (according to your suggestion) to run test on remote machine. It is fine, but I like agent-less or semi agent-less solutions more. What do I mean? If for example your remote machine is Unix you can perform SSH or Telnet connection and run command line. In this case you can create mvn or ant script, copy to remote machine using ssh and then run it. The script will run your tests. So it is almost agent less. You just require java installation and SSH support.
If remote machine is windows you can use either Telnet or WMI. So, if security is not an issue but you need cross platform support use Telnet.
Please do not hesitate to contact me if you need more assistance concerning SSH/Telnet.
我自己没有做过(我的测试是本地的),但这里有一些可以工作的东西:
I haven't done it myself (my tests are local), but here are some stuff that could work:
在我的解决方案中,我将启动本地 JNDI 服务器并添加一个远程对象(实现远程接口的对象),然后您可以使用该远程对象来同步本地 IDE 和远程服务器或其他地方。
In my solution, I will lunch a local JNDI server and add a remote object (an object implement the Remote interface), then you could use the remote object to sync your local IDE and remote server or other place.