如何指示异步测试用例失败

时间:2019-01-28 09:55:32

标签: maven junit vert.x

我在Maven项目的junit测试中有以下代码:

package huru;

import huru.util.Async;
import io.vertx.core.Vertx;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Arrays;

@RunWith(VertxUnitRunner.class)
public class AsyncTest {


  @Test
  public void test(TestContext tc) {

    io.vertx.ext.unit.Async z = tc.async();

    Async.Parallel(Arrays.asList(

      v -> {
        v.done(null, null);
      }

    ), (e, results) -> {

      if(e != null){
        z.complete();
      }
      else{
        z.complete();
      }

    });
  }

}

但是,在io.vertx.ext.unit.Async实例中,我仅看到以下方法:

enter image description here

因此,除了调用z.complete()之外,如何调用z.fail()?我应该抛出一个错误吗?

1 个答案:

答案 0 :(得分:1)

您可以简单地从fail()调用TestContext

tc.fail()
相关问题