Search in sources :

Example 1 with TestSuite

use of io.vertx.ext.unit.TestSuite in project sonar-java by SonarSource.

the class A method test_saveUser.

@Test
public void test_saveUser() {
    // Compliant even if this test may not be run correctly - assertion is present
    TestSuite suite = TestSuite.create("suite_user_save");
    HttpClient client = vertx.createHttpClient();
    suite.test("user_save", context -> {
        client.getNow(port, host, requestURI, resp -> {
            resp.bodyHandler(body -> {
                // assertion
                context.assertNotEquals("created", body.toString());
                client.close();
            });
        });
    });
}
Also used : TestSuite(io.vertx.ext.unit.TestSuite) HttpClient(io.vertx.core.http.HttpClient) Test(org.junit.Test)

Example 2 with TestSuite

use of io.vertx.ext.unit.TestSuite 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

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