如何处理`黄瓜'中的'@ WHEN`不满意条件?

时间:2018-04-27 09:18:43

标签: java junit cucumber language-features cucumber-junit

在我的情况下,我在Junit中使用了黄瓜,在@WHEN中我使用了逻辑进行测试。当我的测试满意时,我的代码转到@THEN。但是当我的代码不满意时,我使用org.Junit.Assert.fail()来测试没有消息的测试,但我得到了以下日志错误:

java.lang.AssertionError
  at org.junit.Assert.fail(Assert.java:86)
  at org.junit.Assert.fail(Assert.java:95)
  at com.abcfinancial.bdd.cucumber.serenity.cucumberstep.BusinessSignUp.validateTheProvidedFields(BusinessSignUp.java:66)
  at ✽.firstname is vikas lastName is jindal password is 1234576 email is bravo@asd.com organization name is abc location name is BananaMans Land Location Location address1 is 123 Main Rd address2 is Near XYZ  city is  Pizzaburg state is Ohio country is United States zipcode is 53421  org email address is vikas@gmail.com(src/test/resources/features/businesssignup/01business_sign_up.feature:8)

但我不想让at ✽.firstname is vikas lastName is jindal password is 1234576 email is bravo@asd.com organization name is abc location name is BananaMans Land Location Location address1 is 123 Main Rd address2 is Near XYZ city is Pizzaburg state is Ohio country is United States zipcode is 53421 org email address is vikas@gmail.com(src/test/resources/features/businesssignup/01business_sign_up.feature:8)行出错。

我的java类是:

public class BusinessSignUp {
private static final Logger applicationLogger = LoggerFactory.getLogger("ApplicationLogger");

GlobalBeans signUpDomaindomain = null;
String threadId = String.valueOf(Thread.currentThread().getId());
Map<String, GlobalBeans> refIdMap = GlobalRefIdMap.getRefIdMapInstance().getRefIdMap();

@Steps
BusinessSignUpSerenity businessSignUpSteps;

@Given("^Tester Name is (.*)$")
public void givenBaseUri(String tester) {
    applicationLogger.info("Tester Name is {}", tester);

}

@When("^firstname is (.*) lastName is (.*) password is (.*) email is (.*) organization name is (.*) location name" +
        " is (.*) Location address1 is (.*) address2 is (.*)  city is  (.*) state is (.*) country is (.*) zipcode" +
        " is (.*)  org email address is (.*)$")
public void validateTheProvidedFields(String firstName, String lastName, String password, String email, String
        orgName, String organizationLocationName, String organizationLocationAddress1, String
                                              organizationLocationAddress2, String organizationLocationCity,
                                      String organizationLocationState, String
                                              organizationLocationCountry, String organizationLocationZip, String
                                              orgEmail) {
    try {
        if (refIdMap.size() == 0) {
            refIdMap = Utility.setBusinessSignupDomain(threadId, firstName, lastName, password, email, orgName,
                    organizationLocationName, organizationLocationAddress1, organizationLocationAddress2,
                    organizationLocationCity, organizationLocationState, organizationLocationCountry,
                    organizationLocationZip, orgEmail);
        }
        signUpDomaindomain = refIdMap.get(threadId);
        applicationLogger.info("Printing domain in BusinessSignUp with  {}", signUpDomaindomain);
        businessSignUpSteps.doSignup(signUpDomaindomain, refIdMap);


    } catch (Exception exception) {
        applicationLogger.error("Printing exception detail {}", exception.getMessage());
        exception.printStackTrace();
        Assert.fail();
    }

}

@Then("^SignUp is(.*)$")
public void success(String message) {
    if (AppConstants.success_message.equals(message.trim())) {
        applicationLogger.info("***** SignUp is : {} *****", message);
    } else {
        applicationLogger.info("***** SignUp is : {} *****", AppConstants.unsuccessful_message);
    }
  }

}

在上面的课程中我使用SignUp代码,其中我使用了如下功能文件:

https://drive.google.com/drive/folders/11K0I-XYE6BzIrzbrAzk8odfaze-S5oRE?usp=sharing

1 个答案:

答案 0 :(得分:0)

在最新的黄瓜版本2.4.0 中,添加有关特征文件的最后一个堆栈跟踪行的类来自cucumber.runtime.StepDefinitionMatch类。确切的方法是 - removeFrameworkFramesAndAppendStepLocation()。这基本上将stacktrace与特征文件(StackTraceElement类的对象)中的相关行相关联。您需要查看来自runStep()方法的电话。

即使你改变了这个,这个类的代码也会在下一个版本中进行相当广泛的改变。