Cucumber-java Basic article

Source: Internet
Author: User

Recently the company advocated rapid testing, before the UI interface automation is really unstable and slow execution, there will always be a lot of strange problems ...

Fast test premise is that the Web response contains only JSON format (in fact, XML format) data, to the HTML and data separation,

This provides great convenience, data validation is easy, and more accurate, continuous integration faster, more accurate positioning problems.

People are very enthusiastic, with a lot of tools,

Choose a good tool to succeed more than half, tools and worry about

The following is a description of the use of cucumber under the title

1. Install cucumber click, http://blog.csdn.net/musen518/article/details/45363911

2. Cucumber Case Structure

A, define features, case set, used to describe multiple scenarios (cases), mainly by testers to write maintenance

b, define steps, step definition, implement real test action, can be a tester or developer write maintenance

3. features file,

Here are two cases (scenario = case)

I. Scenario one, with parameters and multiple data-driven tests

II. Scenario two, without parameters, can only test one piece of data

Feature:testsuite Scenario Outline: Login Success Test (with multiple parameters) Given Enter user name: < username > and enter password: < password > When click Login Then login successful Examples: | User name |      password | | name1 |      PWD1 | | name2 |  Pwd2 | Scenario: Login Failure Test (no parameters) Given Enter user name: Name3 and enter password: PWD3 when click Login T

4. Steps Definition

A) given annotations, regular expressions, for matching feature file contents, implementing steps and obtaining parameters

b) When annotation, action event step, indicating action behavior

c) then annotations, asserting

d) More annotations can go, cucumber official documents: https://cukes.info/docs/

</pre><pre name= "code" class= "java" >package test;import Cucumber.api.java.en.given;import Cucumber.api.java.en.then;import Cucumber.api.java.en.when;public class Testcasesteps {    @Given ("^ Input user name: (\\w+) $ ") Public    void Enter the user name (String user name)  {        System.out.println (user name);    }        @Given ("^ Enter password: (\\w+) $") Public    void Enter password (String password)  {        System.out.println (password);    }        @When ("^ Click Login $") public    void Click Login ()  {        System.out.println ("Login ...");    }        @Then ("^ Login succeeded $") public    void Login succeeded ()  {        System.out.println ("Login succeeded");    }        @Then ("^ Login failed $") Public    void Login failed () throws Exception  {        throw new Exception ("Login Failed");}    }

4. Implementation cases

A) through the Eclipse plugin, the Eclipse cucumber plugin must be installed

Select the feature file, right-click Run as, select Cucumber feature\


b) Execute via JUnit, requires load dependency, this way without installing the Cucumbereclipse plugin (testng similar)

I. Cucumber-junit-1.2.2.jar

II. Hamcrest-core-1.3.jar

III. Junit-4.12.jar





Cucumber-java Basic article

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.