简体   繁体   English

Java 8中的单元测试黄瓜步骤

[英]unit test cucumber step in java 8

I am writing integration tests in Cucumber-Java8, and was wondering if there was a simple way to unit test steps? 我正在用Cucumber-Java8编写集成测试,并且想知道是否存在一种简单的单元测试步骤的方法?

if I have a step class: 如果我有阶梯课:

public class MySteps implement En {
    public MySteps() {
        Given("a {string} is passed", (String string) {
            assertTrue(string.equals("hi");
        });
    }
}

How could i test what is in the constructor? 我如何测试构造函数中的内容?

cheers 干杯

Given that your step basically is already a test, I would not write an extra unit test for it. 鉴于您的步骤基本上已经是测试,因此我不会为此编写额外的单元测试。 However, you probably are thinking about testing a very complex step where it might makes sense. 但是,您可能正在考虑测试可能有意义的非常复杂的步骤。

You can use the JUnit and simply call the constructor and methods of your step 'class'. 您可以使用JUnit并简单地将步骤的“类”的构造函数和方法调用。 As already commented for the given step it doesn't seem to make any sense because there is not much going on in addition to the assertion. 正如已经针对给定步骤所评论的那样,这似乎没有任何意义,因为除了断言之外,没有其他事情在进行。 And if you want to test a complex step, it might be a better option to extract the complex part and test it without the involvement of the step. 而且,如果您想测试一个复杂的步骤,那么提取复杂的部分并在不涉及该步骤的情况下对其进行测试可能是一个更好的选择。

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

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