[Technical Design][Draft] Unified Functional Test Framework #134
MuhammedIrfan
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Introduction
This design document provides a high-level design of our customized framework that will drive automated functional testing of BTP. We are developing this framework to be as generic as possible so that it can adapt to automate any blockchain that we plan to test in the future. The application is developed in Rust which will interact with the test framework in python using Behave BDD(Behavior Driven Development) approach.
Terminology
Considerations
Behave is a tool used for Behavior-driven development (BDD) in Python programming language. In an Agile development framework, BDD creates a culture where testers, developers, business analysts, and other stakeholders of the project can contribute to the software development.
Having a unified framework can use the same tests for multiple blockchains. Having worked with NEAR, it has a sandbox VM to run contracts that can be used for functional testing. Our previous implementation used rust for writing test cases. Going forward we would like to use python for the test framework to unify and reuse the tests across multiple integrations.
Design
High-level Architecture
Components
Test Helper
In order to initiate and deploy the smart contracts, the test-helper play a major role. Each blockchain will have a dedicated test helper to help with initialization and deployment. Test helper is written in rust.
Test helper consists of 2 folders mainly:
Actions:
Ex: get_owner , add_owner
Types:
Test Interface
Test Interface is developed in such a way that it can interact with the test helper of any blockchain. Python automation suite will be accessing this interface to call methods in test helper which in turn will communicate with smart contracts in blockchain.
Test Interface will be written in Rust but it will be wrapped with python bindings so that python test cases can access the test interface.
Python Behave BDD Implementation
The basic structure of tests using Behave consists of the feature file, the step definition file, and so on. Feature file should be present under a folder called features and a subfolder called steps should also be created where step definition will be written in python.
Implementation
PyO3 supports the following software versions:
PyO3 can be used to generate a native Python module and to do this we need to install Maturin.
Install Maturin:
pip install maturin
cargo install maturin
cargo install --git https://github.com/PyO3/maturin.git maturin
Configuration
Major changes or additions are done in configuration files like cargo.toml, lib.rs and pyproject.toml.
When you create a project using ‘maturin init’ cargo.toml, lib.rs and pyproject.toml files are automatically generated with all dependencies required. You can use that project or copy the configuration to a project where testing has to done.
we can make rust function callable from Python using
The following code follows illustrates the above steps in the same order:
Now that we have a rust program with python annotations ready we can use them in test cases by implementing Behave BDD structure.
Here’s a brief explanation of the files:
Owner.feature → Here is an example of a feature file in Gherkin language.
Feature: detailed description of the feature.
Manage_owner.py → Example of step definition file based on the above feature.
To Run Test Cases
To run test cases here are the steps.
Report
To create a JUnit report, run the command given below
behave –junit
A folder called as the reports gets generated within the project, having the name TESTS-.xml.
Conclusion
Here is why the proposed automation suite is best suited for functional testing.
scenario and contribute towards improvising test scenarios/user stories.
Beta Was this translation helpful? Give feedback.
All reactions