没有为参数[io.vertx.ext.unit.TestContext arg0]

时间:2018-07-10 13:23:00

标签: java junit vert.x vertx-verticle

我正在尝试为与vertx相关的东西编写一个测试用例。

这是我的代码

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;

import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpServer;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;

@RunWith(VertxUnitRunner.class)
public class MyJUnitTest {

static Vertx vertx;
static HttpServer server;

@BeforeAll
public static void before(TestContext context) {
    Async async = context.async();
    vertx = Vertx.vertx();
    server = vertx.createHttpServer().requestHandler(req -> req.response().end("foo")).listen(8080,
            context.asyncAssertSuccess());
    System.out.println("Service started....");
    async.complete();
}

@AfterAll
public static void after(TestContext context) {
    vertx.close(context.asyncAssertSuccess());
}

@Test
public void test1(TestContext 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());
            client.close();
            async.complete();
        });
    });
}}

出现以下错误:

  

org.junit.jupiter.api.extension.ParameterResolutionException:没有在可执行文件[public static void remoteprocess.java.samples.MyJUnitTest.before(io.io)中为参数[io.vertx.ext.unit.TestContext arg0]注册ParameterResolver。 vertx.ext.unit.TestContext)]。       在org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameter(ExecutableInvoker.java:191)       在org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameters(ExecutableInvoker.java:174)       在org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameters(ExecutableInvoker.java:135)       在org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:116)       在org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda $ invokeBeforeAllMethods $ 5(ClassTestDescriptor.java:228)       在org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)处       在org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeBeforeAllMethods(ClassTestDescriptor.java:227)       在org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before(ClassTestDescriptor.java:151)处       在org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before(ClassTestDescriptor.java:61)       在org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda $ execute $ 3(HierarchicalTestExecutor.java:80)中       在org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)       在org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:77)       在org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda $ null $ 2(HierarchicalTestExecutor.java:92)中       在java.util.stream.ForEachOps $ ForEachOp $ OfRef.accept(未知来源)       在java.util.stream.ReferencePipeline $ 2 $ 1.accept(未知来源)       在java.util.Iterator.forEachRemaining(未知来源)       在java.util.Spliterators $ IteratorSpliterator.forEachRemaining(未知来源)       在java.util.stream.AbstractPipeline.copyInto(未知来源)       在java.util.stream.AbstractPipeline.wrapAndCopyInto(未知来源)       在java.util.stream.ForEachOps $ ForEachOp.evaluateSequential(未知源)       在java.util.stream.ForEachOps $ ForEachOp $ OfRef.evaluateSequential(未知源)       在java.util.stream.AbstractPipeline.evaluate(未知来源)       在java.util.stream.ReferencePipeline.forEach(未知来源)       在org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda $ execute $ 3(HierarchicalTestExecutor.java:92)中       在org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)       在org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:77)       在org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:51)       在org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43)处       在org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)       在org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)       在org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)       在org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:86)       在org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)       在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)       禁止:org.junit.jupiter.api.extension.ParameterResolutionException:在可执行文件[public static void remoteprocess.java.samples.MyJUnitTest.after(io.vertx)中未为参数[io.vertx.ext.unit.TestContext arg0]注册ParameterResolver .ext.unit.TestContext)]。           在org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameter(ExecutableInvoker.java:191)           在org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameters(ExecutableInvoker.java:174)           在org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameters(ExecutableInvoker.java:135)           在org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:116)           在org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda $ null $ 6(ClassTestDescriptor.java:242)           在org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)处           在org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda $ invokeAfterAllMethods $ 7(ClassTestDescriptor.java:241)           在java.util.ArrayList.forEach(未知来源)           在java.util.Collections $ UnmodifiableCollection.forEach(未知来源)           在org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeAfterAllMethods(ClassTestDescriptor.java:241)           在org.junit.jupiter.engine.descriptor.ClassTestDescriptor.after(ClassTestDescriptor.java:162)           在org.junit.jupiter.engine.descriptor.ClassTestDescriptor.after(ClassTestDescriptor.java:61)           在org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda $ execute $ 3(HierarchicalTestExecutor.java:96)中           ...另外27个

请帮助解决此问题。

1 个答案:

答案 0 :(得分:0)

问题是您没有用vertx信息“包装”文本。请检查文档:

https://vertx.io/preview/docs/vertx-junit5/java/

此外,您还应该使用注释@ExtendWith(V​​ertxExtension.class)在方法中使用该参数。

致谢