Initial Knowledge of gauge automated testing framework (2)

Source: Internet
Author: User

I will continue to introduce the gauge automated testing tool if you are interested in the tool.

Gauge is essentially a BDD (behavior driven development) testing framework. Therefore, you must first understand how BDD operates.

BDD contains two parts:Software behavior description. The other part is:Write test code for description.

First, the behavior description file is described as follows.

# Calculator I want to implement a simple calculator, which can add, subtract, multiply, and divide two numbers. # Test addition * Create a calculator class. * If the add method is used, the result of 3 plus 5 is 8.

Create a behavior Filespecs/calculator.spec, Translate the above content:

# CalculatorI'm implementing a simple calculator that can add, subtract, multiply, and divide two numbers.## Test addition* Create a Class Calculator.* Using Add method, digital "3" plus "5" result is "8".

The only difference from other BDD frameworks is that the guage behavior description file is written by the markdown statement.
For example, the python BDD framework behave is composed of some keywords (feature, scenario, given, when, then, etc ).

# -- FILE: features/example.featureFeature: Showing off behave    Scenario: Run a simple test        Given we have behave installed           When we implement 5 tests    Then behave will test them for us!

Okay, I think you can understand the behavior file I wrote with markdown above. If you really don't understand the markdown syntax. Maybe this online tool can help you learn quickly:

Http://mahua.jser.me/

Next, write code for the behavior file. Createsetp_impl/calculator.pyFile.

from getgauge.python import step@step("Create a Class Calculator.")def create_Calculator():    calc = Calculator()@step("Using Add method, digital <a> plus <b> result is <c>.")def test_add(a, b, c):    calc = Calculator()    result = calc.add(a, b)    assert result == int(c)class Calculator():    def add(self, x, y):        return int(x) + int(y)

In the implementation test code file@step()The decorator references the steps in the behavior description file and uses the data<Variable>Replace the variable in the test procedure.

Strictly speaking,Calculator()Class implementation should be implemented in a separate file. This is just to save time.

Run the gauge run specs command in the project root directory.

View the test report.

What if I want to add test cases? It is very simple. You only need to add a behavior description.

……## Test addition big number* Create a Class Calculator.* Using Add method, digital "301" plus "578" result is "879".

The question is, what type of test can gauge be used for? Here are some examples for your reference.
Https://getgauge-examples.github.io/

Initial Knowledge of gauge automated testing framework (2)

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.