针对 http 服务器的集成测试 - junit?
我想针对 http 服务器进行集成测试。到目前为止,我只有使用 junit 进行单元测试的经验。
我有两个要求:框架必须有一个 Maven 插件,并且测试用例代码必须干净 - 所以没有脏黑客和样板代码。
普通 JUnit 适合单元测试,@Test 方法是单独的。但对于集成测试,我必须处理几个必须交换某种状态(变量)的依赖步骤。
我已经阅读过:
我们可以使用 JUNIT 进行自动化集成测试吗? 和 在测试之间传递 JUnit 数据 并得出我不喜欢的结论单元测试中的静态字段,我不想使用 TestNG 并在测试上添加依赖注释,我不想将我的测试放入一个长的不可读的测试方法中。
我想更多地了解一些语法,例如:
public class MyIntegrationTest() {
@Step
public void testCreate(Context context) {context.put("foo");}
@Step
public void testUpdate(Context context) {context.get();}
@Step
public void testDelete(Context context) {context.get()}
}
所以我想增强/使用 ?Unit ,使其以上下文实例作为参数执行 @Step 方法。这些方法必须由框架按顺序调用,不能单独调用。在完美的世界中,所有?Unit guis都会像@Test一样显示@Step,但这是可选的......
有任何提示如何做到这一点吗?
扬
I want to to integration tests against an http server. So far I have only experiences with junit for unit testing.
I have two requirements: The framework must have a maven plugin and the tests cases code must be clean - so no dirty hacks and no boilerplate code.
Plain JUnit is good for unit testings, @Test methods are individual. But for integration testing I have to process several dependant steps which must exchange some kind of state (variables).
I already read:
Can we use JUNIT for Automated Integration Testing? and Passing JUnit data between tests and came to the conclusion that I don't like static fields in unit test and I don't want to use TestNG and add dependency annotations on tests and I don't want to put my test into one long unreadable test method.
I though more about some syntax like:
public class MyIntegrationTest() {
@Step
public void testCreate(Context context) {context.put("foo");}
@Step
public void testUpdate(Context context) {context.get();}
@Step
public void testDelete(Context context) {context.get()}
}
So I want to enhance/use ?Unit in a way that it executes @Step methods with a context instance as argument. The methods must be called by the framework in order and cannot be called individually. In a perfect world, all ?Unit guis would show the @Step like an @Test but this is optional...
Any hints how to do this?
Jan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一点是检查 Maven Failsafe 插件用于使用 Maven 进行集成测试。其次,您必须根据 Maven FailSafe 插件 之后,您应该能够简单地使用 Maven 运行集成测试(通过 mvn clean verify)。
因此,这意味着您必须将集成测试命名为 MyIntegrationIT.java...要定义执行顺序,您必须使用与 JUnit 不同的框架,TestNG 可能支持这种需求,但您已经排除了它。所以问题是您想要进行什么样的测试?页面流等可能值得一看 JWebUnit 可能值得......
The first point is to check the Maven Failsafe Plugin which is intended for doing integration tests with Maven. Second you have to name your Integration tests based on the conventions used by Maven FailSafe Plugin after that you should be able to run your integration tests simply with maven (by mvn clean verify).
So this means you have to name your integration test like MyIntegrationIT.java...To define the order of executions you have to use a different framework than JUnit may be TestNG which supports this kind of needs, but you already excluded it. So the questions is what kind of tests would you like to do? Page-flows etc. may be a look at JWebUnit might be look worth...
您可能还需要考虑http://httpunit.sourceforge.net/。它对于检查响应是否从 http 服务器返回非常有用。
但是,它不执行@Step 功能。通常我会这样做:
You might also want to consider http://httpunit.sourceforge.net/. It's useful for checking to see if responses come back from the http server.
However, it doesn't do the @Step functionality. Normally I'd do that by :