Search in sources :

Example 1 with TestOptions

use of io.vertx.ext.unit.TestOptions in project vertx-examples by vert-x3.

the class VertxUnitTest method run.

// Not yet detected
@CodeTranslate
public void run() {
    TestOptions options = new TestOptions().addReporter(new ReportOptions().setTo("console"));
    TestSuite suite = TestSuite.create("io.vertx.example.unit.test.VertxUnitTest");
    suite.before(context -> {
        vertx = Vertx.vertx();
        vertx.createHttpServer().requestHandler(req -> req.response().end("foo")).listen(8080, context.asyncAssertSuccess());
    });
    suite.after(context -> {
        vertx.close(context.asyncAssertSuccess());
    });
    // Specifying the test names seems ugly...
    suite.test("some_test1", context -> {
        // Send a request and get a response
        HttpClient client = vertx.createHttpClient();
        Async async = context.async();
        client.getNow(8080, "localhost", "/", resp -> {
            resp.bodyHandler(body -> context.assertEquals("foo", body.toString("UTF-8")));
            client.close();
            async.complete();
        });
    });
    suite.test("some_test2", context -> {
        // Deploy and undeploy a verticle
        vertx.deployVerticle("io.vertx.example.unit.SomeVerticle", context.asyncAssertSuccess(deploymentID -> {
            vertx.undeploy(deploymentID, context.asyncAssertSuccess());
        }));
    });
    suite.run(options);
}
Also used : CodeTranslate(io.vertx.codetrans.annotations.CodeTranslate) TestSuite(io.vertx.ext.unit.TestSuite) Async(io.vertx.ext.unit.Async) TestOptions(io.vertx.ext.unit.TestOptions) HttpServer(io.vertx.core.http.HttpServer) Vertx(io.vertx.core.Vertx) ReportOptions(io.vertx.ext.unit.report.ReportOptions) HttpClient(io.vertx.core.http.HttpClient) TestSuite(io.vertx.ext.unit.TestSuite) TestOptions(io.vertx.ext.unit.TestOptions) Async(io.vertx.ext.unit.Async) HttpClient(io.vertx.core.http.HttpClient) ReportOptions(io.vertx.ext.unit.report.ReportOptions) CodeTranslate(io.vertx.codetrans.annotations.CodeTranslate)

Aggregations

CodeTranslate (io.vertx.codetrans.annotations.CodeTranslate)1 Vertx (io.vertx.core.Vertx)1 HttpClient (io.vertx.core.http.HttpClient)1 HttpServer (io.vertx.core.http.HttpServer)1 Async (io.vertx.ext.unit.Async)1 TestOptions (io.vertx.ext.unit.TestOptions)1 TestSuite (io.vertx.ext.unit.TestSuite)1 ReportOptions (io.vertx.ext.unit.report.ReportOptions)1