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
The <code>Depends</code> Annotation defines the dependencies of a test method.
(完整版)软件测试技术试验报告--JUnit的基本应用.pdf(完整版)软件测试技术试验报告--JUnit的基本应用.pdf(完整版)软件测试技术试验报告--JUnit的基本应用.pdf(完整版)软件测试技术试验报告--JUnit的基本应用.pdf...
(完整版)软件测试技术试验报告--JUnit的基本应用.docx(完整版)软件测试技术试验报告--JUnit的基本应用.docx(完整版)软件测试技术试验报告--JUnit的基本应用.docx(完整版)软件测试技术试验报告--JUnit的基本应用.docx...
赠送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-...
赠送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
软件测试实验3--Junit单元测试.docx软件测试实验3--Junit单元测试.docx软件测试实验3--Junit单元测试.docx软件测试实验3--Junit单元测试.docx软件测试实验3--Junit单元测试.docx软件测试实验3--Junit单元测试.docx...
赠送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-...
官方版本,亲测可用
Kotlin对junit的测试支持 org.jetbrains.kotlin/kotlin-test-junit/1.5.0-RC/kotlin-test-junit-1.5.0-RC.jar
COMP1206-DAGSort-JUnit-Test 创建了一个JUnit测试来测试有效的DAG图排序算法。 可以使用以下命令运行: java -cp .:junit.jar:hamcrest-core.jar org.junit.runner.JUnitCore DAGSortTest 这不会测试特定的输出...
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 这个网页会间歇性抽风,下载后分享一下
junit-platform-launcher-1.7.0.jarjunit-platform-launcher-1.7.0.jar
分别是两个版本的, 因为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...
spring-Test,Junit4 jar,和测试代码
最简单的方法是将karma-junit-reporter保留为package.json的devDependency。 { " devDependencies " : { " karma " : " ~0.10 " , " karma-junit-reporter " : " ~0.3 " } } 您可以通过以下方法简单地做到这...