http://developer.eclipsesource.com/restfuse/
Everything you need to know to get started is displayed in the snippet below which is a fully functional HTTP Test.
1234567891011121314 |
@RunWith( HttpJUnitRunner.class )
public class RestfuseTest {
@Rule
public Destination destination = new Destination( "http://restfuse.com" );
@Context
private Response response; // will be injected after every request
@HttpTest( method = Method.GET, path = "/" )
public void checkRestfuseOnlineStatus() {
assertOk( response );
}
}
|
This test sends a request to restfuse.com before the test method will be executed. After the request returns the response will be injected by assigning the @Context
annotated response
field before the test method will be executed. This field can be used within the test method to test the content of the response. By the way, restfuse also supports the testing of asynchronous REST services.
Regardless for what you are using asynchronous mechanisms, you only have two options to deal with it: Polling or Callbacks. Both methods are supported by restfuse.
Polling
When you need to poll an asynchronous service more than once you can use the @Poll
annotation. A simple example looks like the one below. The service in this example will be called 5 times as the same as the test method. The response for each request will be injected into the test object and can be tested.
Callbacks
To use a callback to test an asynchronous service you can use the @Callback
annotation on you test method. Restfuse will start a server on the defined port and registers a resource. The test fails if the attached resource was not called. Within the resource you can test the incoming request. A simple callback example looks like this.
1234567891011121314151617181920 |
@RunWith( HttpJUnitRunner.class )
public class RestfusePollTest {
@Rule
public Destination destination = new Destination( "http://restfuse.com" );
@Context
private Response response;
@Context
private PollState pollState
@HttpTest( method = Method.GET, path = "/asynchron" )
@Poll( times = 5, interval = 500 )
public void testAsynchronousService() {
Response currentResponse = pollState.getRespone( pollState.getTimes() );
assertEquals( currentResponse, response );
}
}
|
123456789101112131415161718192021222324 |
@RunWith( HttpJUnitRunner.class )
public class RestfuseCalbackTest {
@Rule
public Destination destination = new Destination( "http://restfuse.com" );
@Context
private Response response;
private class TestCallbackResource extends DefaultCallbackResource {
@Override
public Response post( Request request ) {
assertNotNull( request.getBody() );
return super.post( request );
}
}
@HttpTest( method = Method.GET, path = "/test" )
@Callback( port = 9090, path = "/asynchron", resource = TestCallbackResource.class, timeout = 10000 )
public void testMethod() {
assertAccepted( response );
}
}
|
Convinced?
相关推荐
struts-junit spring-mock spring-test junit等的javadoc.jar格式的API文档,直接导入Eclipse/MyEclipse/Netbeans等IDE即可实现快速API查询。 包含以下文件: ...struts2-junit-plugin avadoc.jar
赠送jar包:powermock-module-junit4-2.0.9.jar; 赠送原API文档:powermock-module-junit4-2.0.9-javadoc.jar; 赠送源代码:powermock-module-junit4-2.0.9-sources.jar; 赠送Maven依赖信息文件:powermock-...
The <code>Depends</code> Annotation defines the dependencies of a test method.
junit-platform-launcher-1.7.0.jarjunit-platform-launcher-1.7.0.jar
赠送jar包:powermock-module-junit4-common-2.0.9.jar; 赠送原API文档:powermock-module-junit4-common-2.0.9-javadoc.jar; 赠送源代码:powermock-module-junit4-common-2.0.9-sources.jar; 赠送Maven依赖信息...
unittest-xml-reporting, 基于 Ant/junit的测试 runner,类似于XML报告 unittest-xml-reportingunittest-xml-reporting是一个,测试 runner,可以以将测试结果保存到可以由生成系统。ide和 持续集成 服务器消耗的XM
junit-platform-engine-1.6.3.jarjunit-platform-engine-1.6.3.jar
赠送jar包:archunit-junit5-api-0.14.1.jar; 赠送原API文档:archunit-junit5-api-0.14.1-javadoc.jar; 赠送源代码:archunit-junit5-api-0.14.1-sources.jar; 赠送Maven依赖信息文件:archunit-junit5-api-...
<pathelement location="path/to/ant-junit-1.7.0.jar"/> <!-- 添加其他库路径 --> </classpath> <formatter type="plain" usefile="false"/> <test name="com.example.YourTestClass" todir="test-reports"/> ...
官方版本,亲测可用
Kotlin对junit的测试支持 org.jetbrains.kotlin/kotlin-test-junit/1.5.0-RC/kotlin-test-junit-1.5.0-RC.jar
《Ant与JUnit结合:ant-junit-1.6.1.jar.zip详解》 在软件开发过程中,测试是不可或缺的一环,而JUnit作为Java语言中最常用的单元测试框架,为开发者提供了便利。同样,Apache Ant作为自动化构建工具,对于项目管理...
COMP1206-DAGSort-JUnit-Test 创建了一个JUnit测试来测试有效的DAG图排序算法。 可以使用以下命令运行: java -cp .:junit.jar:hamcrest-core.jar org.junit.runner.JUnitCore DAGSortTest 这不会测试特定的输出...
JUnit 4 是一款广泛应用于Java开发中的单元测试框架,它极大地简化了测试代码的编写和执行。作为Java事实上的标准单元测试库,JUnit 4 的易用性和灵活性使其成为开发者首选的测试工具。本文将深入讲解JUnit 4的关键...
Kotlin对junit的测试支持 org.jetbrains.kotlin/kotlin-test-junit/1.1.4-2/kotlin-test-junit-1.1.4-2.jar
junit-4.11-4.12-harcrest-core1.3 https://github.com/junit-team/junit/wiki/Download-and-Install 这个网页会间歇性抽风,下载后分享一下
JUnit5相关的 JUnit Jupiter.jar依赖包,主要包含: junit-jupiter-5.5.1.jar,junit-jupiter-api-5.5.1.jar,junit-jupiter-engine-5.5.1.jar,junit-jupiter-params-5.5.1.jar,junit-jupiter-api-5.4.2.jar,...
这个压缩包"powermock-easymock-junit-1.5.4.zip"很可能包含了这三个库的特定版本1.5.4,便于开发者下载和集成到自己的项目中。 首先,我们来详细了解一下PowerMock。PowerMock是一个扩展了其他模拟框架(如...
分别是两个版本的, 因为spring做单元测试的时候, 是很容易出现版本不兼容的情况, 所以我将我用到的jar包分享出来,zip包中内容:hamcrest-core-1.3、junit4.4、junit-4.12、spring_test2.5.5、spring-test-3.2.0....
<artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven...