Cucumber_java from Getting Started to mastering (5) Creating a Cucumber_java project with Maven

Source: Internet
Author: User

Cucumber Java from Getting started to mastering (5) Creating cucumber Java projects with Maven

In the first few sections we have been aware of the basic functions of cucumber and the basic process of BDD testing, and we have progressively reconstructed, step-by-step toward the target. These practices are small and beautiful, but the drawback is that we are progressing slowly in the engineering of the project.

At present, there are some problems in the engineering of our project:

    • Dependency Package Management: Our Dependency package management is a very primitive ecosystem. If cucumber Java upgrade or other dependent component upgrades, the trouble we encounter is predictable;
    • Build system: Our building system is still in the era of slash and burn, only bat script obviously can't stand the repeated toss of complex long-term project;
    • IDE: We are only using a plain text editor, although nothing bad, but using the IDE is good for beginners . Of course, if you are skilled in the big God-level characters, with Notepad to write Java can not be;
Solve the problem of engineering

Let's look at some of the solutions to improve the engineering problem, which is called technology pre-research.

    • Use Maven to solve our dependency package management and build issues;
    • Use eclipse as our Java IDE;
Download Eclipse and configure

Download eclipse here and note the difference between the 32-bit version and the 64-bit version;

After the download installation is complete, install the Eclipse+maven plugin m2eclipse. The installation process is as follows:

First click on the menuHelp-Istall Software

Enter in the work with in the popup window http://download.eclipse.org/technology/m2e/releases and follow the instructions to

The m2eclipse should be installed successfully after the next step.

New MAVEN Project

Selection File-New-Other , as shown in

Then choose Maven Projectand click Next

And then directly next.

Then Group Id fill in the info.itest, fill in the Artifact Id todo_list. Click Finish

Then double-click to open the pom.xml file

Enter the editing state as shown in

Replace the pom.xml with the following code

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >< Modelversion>4.0.0</modelversion><groupid>info.iest</groupid><artifactid>todo_list </artifactid><version>0.0.1-snapshot</version><packaging>jar</packaging><name >todo_list</name><url>http://maven.apache.org</url><properties><cucumber.version >1.2.4</cucumber.version><junit.version>4.12</junit.version><java.version>1.8</ java.version><maven.compiler.version>3.3</maven.compiler.version></properties>< dependencies><dependency><groupid>info.cukes</groupid><artifactid>cucumber-java< /artifactid><version>${cucumber.version}</version><scope>test</scope></ Dependency><dependency>< groupid>info.cukes</groupid><artifactid>cucumber-junit</artifactid><version>${ cucumber.version}</version><scope>test</scope></dependency><dependency>< groupid>junit</groupid><artifactid>junit</artifactid><version>${junit.version}</ Version><scope>test</scope></dependency></dependencies><build><plugins> <plugin><groupid>org.apache.maven.plugins</groupid><artifactid>maven-compiler-plugin </artifactid><version>${maven.compiler.version}</version><configuration><encoding >utf-8</encoding><source>${java.version}</source><target>${java.version}</target ><compilerargument>-werror</compilerargument></configuration></plugin></plugins ></build></project>

Note: Please replace the corresponding Java version of java.version here.

Configuration and Operation Cucumber

Open the AppTest.java file and replace it with the following code

Package Info.iest.todo_list;import Cucumber.api.cucumberoptions;import Cucumber.api.junit.cucumber;import Org.junit.runner.RunWith, @RunWith (cucumber.class) @CucumberOptions (plugin={"Pretty"}, features={"src/test/ Features "}) public class Apptest {}

  

    1. 然后在test文件夹下创建features文件夹,并创建todo.feature文件,如所示

Edit the Todo.feature file and enter the following:

#language: ZH-CN function: Task management    Scenario outline: Completing a task        assuming I have <total> tasks on my task List        when I finish the <finished> task,        then I have the rest. <left> Unfinished Task                Example:        | total | finished | left |        |   3   |    1     |   2  |        |   5   |    1     |   4  |

  

    1. Nothing new is the code we reconstructed in the last section.

Then right-click Todo_list in the Package explorer and select Run As-maven Test, as shown in

When the run is complete, the result should be as shown

So far, we have configured the cucumber development environment with MAVEN and completed the smoke test. In the next section, we will transplant the todolist from the previous sections to this MAVEN project





Cucumber_java from Getting Started to mastering (5) Creating a Cucumber_java project with Maven

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.