简体   繁体   English

您的测试套件是否需要 JUnit Engine 才能运行?

[英]Is JUnit Engine required for your test suite to run?

Does a test suite requires junit-jupiter-engine as a dependency, or junit-jupiter-api is enough?测试套件是否需要junit-jupiter-engine作为依赖项,还是junit-jupiter-api就足够了?

Under a post in Stack Overflow - Difference between junit-jupiter-api and junit-jupiter-engine , I have found that both dependencies are essential for our test suite to run.在 Stack Overflow - Difference between junit-jupiter-api and junit-jupiter-engine 的一篇文章中,我发现这两个依赖项对于我们的测试套件的运行都是必不可少的。 However, excersising the following simple test suite works without having the former dependency.但是,执行以下简单测试套件可以在没有以前的依赖关系的情况下工作。

@Test
void testNull() {
    assertThatThrownBy(() -> {
        strategy.sort(null);
    }).isInstanceOf(NullPointerException.class);
}

@Test
void testEmptyArray() {
    int[] arr = new int[0];
    strategy.sort(arr);

    assertThat(arr).isEmpty();
}

@Test
void testUniqueEntries() {
    int[] arr = {1, 2, 14, 3, 45, 7, 24, 13};
    int[] expected = {1, 2, 3, 7, 13, 14, 24, 45};
    strategy.sort(arr);

    assertThat(arr).isEqualTo(expected);
}

@Test
void testDuplicationEntries() {
    int[] arr = {1, 5, 3, 7, 4, 3, 8, 2};
    int[] expected = {1, 2, 3, 3, 4, 5, 7, 8};
    strategy.sort(arr);

    assertThat(arr).isEqualTo(expected);
}

I think I'm yet incapable of telling the concrete difference between the engine and the API, so I would appreciate any comment on the topic.我想我还不能说出引擎和 API 之间的具体区别,所以我希望能对这个话题发表任何评论。 (A real-world analogy would be of a great help.) (现实世界的类比会很有帮助。)

Yes, you need the junit-jupiter-engine dependancy to trigger the tests during your builds.是的,您需要junit-jupiter-engine依赖项来在构建期间触发测试。

The API is just the tooling that helps you writing junit tests, the engine runs the tests. API 只是帮助您编写 junit 测试的工具,引擎运行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM