在junit中配置系统测试
目前,我们有一个专用工具用于在 Web 服务上运行系统测试,但我一直在考虑将其重写为可在 jUnit4 中托管。
这将为我们带来几个优势,包括 Java 设置和断言结果的全部功能,以及希望有一种更简单的运行测试的方法(从 CI 和 IDE 中)。
然而,测试需要配置一个 URL 来进行测试(目前初始化本地 servlet 进行测试是不切实际的)。鉴于此,尝试将其托管在 jUnit 中仍然是一个好主意吗?如果是这样,添加配置的最佳方法是什么?
We currently have a dedicated tool for running system tests on our web services, but I've been thinking of re-writing it to be hostable within jUnit4.
This would give us several advantages, including the full power of Java to set up and assert results, as well as hopefully a simpler method of running the tests (both from CI and the IDE).
However, the tests would need a URL configured for it to test against (it is currently too impractical to initialise a local servlet for testing). Given this, is it still a good idea to try and host it in jUnit? If so, what's the best way to add the configuration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于您将如何运行单元测试。我通常使用 Maven,然后你有一个 test/resources 目录,可以在其中存储测试设置。
您可以将 spring 与 AbstractDependencyInjectionSpringContextTests 结合使用(它为您提供 spring 注入配置,您可以将主 spring 配置交换为测试版本)
这里是关于在eclipse中配置junit的讨论
It depends on how you will be running your unit tests. I normally use maven, then you have a test/resources directory where you can store the test setup.
You can use spring with AbstractDependencyInjectionSpringContextTests (which gives you spring-injected configuration, you can swap the main spring config for a test version)
Here is a dicussion about configuring junit in eclipse
如果您正在进行非单元测试,TestNG 可能是比 JUnit 更好的选择。更具体地说,数据提供者似乎非常适合您描述的场景(示例在这里)。数据提供者几乎可以从任何地方检索他们的数据:文本/属性/xml/Excel 文件、数据库、远程主机等...
If you're doing non-unit testing, TestNG might be a better option than JUnit. More specifically, data providers seem like they would be a good fit in the scenario you describe (example here). Data providers can retrieve their data pretty much from anywhere: a text/properties/xml/Excel file, a database, a remote host, etc...