Coder Social home page Coder Social logo

kmadej / openlmis-contract-tests Goto Github PK

View Code? Open in Web Editor NEW

This project forked from openlmis/openlmis-contract-tests

0.0 0.0 0.0 882 KB

Contract tests for OpenLMIS v3

Home Page: http://openlmis.org

License: GNU Affero General Public License v3.0

Shell 1.79% Java 60.12% Gherkin 38.09%

openlmis-contract-tests's Introduction

openlmis-contract-tests

This repository is intended to contain contract tests of OpenLMIS 3.0

Contract tests should be organized around business scenarios that requires multiple services to work together.

Contract tests should be sending real http requests to and verifying real http response from running services. Mocking and stubbing techniques should reside within integration tests of each single service.

Hypothetical Example

For a certain business scenario named A, it requires:

  1. a post end point of service X
  2. a get end point of service Y

to work together.

In that case, we should create a number of contract tests in this repository, which of course would call those two end points. All of them organized in the same suite under business scenario A's name.

Then in service X's CI pipeline we could have:

run X individual job -> run contract tests that involves X(including scenario A) -> other steps

And in service Y's CI pipeline we could have:

run Y individual job -> run contract tests that involves Y(including scenario A) -> other steps

The example above is simple, it involves only 2 services and 2 end points.

However, the

Quick Start

  1. Fork/clone this repository from GitHub.

git clone https://github.com/OpenLMIS/openlmis-contract-tests.git

  1. Add an environment file called settings.env to the root folder of the project, with the required project settings and credentials. For a starter environment file, you can use this one. e.g.
cd openlmis-requisition
curl -o settings.env -L https://raw.githubusercontent.com/OpenLMIS/openlmis-ref-distro/master/settings-sample.env
  1. Develop w/ Docker by running docker-compose run contract_tests

Running

Run with a script: "run_contract_tests.sh". Such as: ./run_contract_tests.sh TBD.yml -v

"TBD.yml" - parameter -> run with specific file name (e.g., "docker-compose.requisition.yml" OR "docker-compose.stockmanagment.yml").

"-v" - parameter -> run clean up after tests.

Script automatically pull actual images before contract tests.

Running locally

Run with a script: "run_local.sh". Such as: ./run_local.sh TBD.yml pull

"TBD.yml" - parameter -> run with specific file name (e.g., "docker-compose.requisition.yml" OR "docker-compose.stockmanagment.yml").

"pull" - parameter -> pull actual images for docker compose file. This is optional.

Output:

  1. build/logs contains output from docker compose
  2. build/nginx.conf contains nginx configuration
  3. ../logs/ contains logs for every service

Principle

applies for more complex situations as well:

  1. organize contract tests by business scenarios
  2. if a certain scenario involves a certain service, run it as a part of that service's pipeline

The intention to organize contract tests in suites is to enable us to run them separately in different pipelines. So that the contract test is ran whenever any service that is involved in this scenario has any code change.

Then intention to put all contract tests in this one repository is to avoid explosion of docker compose files in service repositories, as interaction between services increase. And it also provides convenience to run all contract test as a part of full regression.

Concrete example

For of scenario of "admin user should be able set up the system". It needs both auth and requisition services.

The following things should be done:

Create cucumber feature file

This file describes a list of steps that the test should take, in a human readability friendly manner. Look at RegularRequisitionTests.feature for example.

Create step definitions

The step definition file provides the feature file with runnable code. Both need to be present for cucumber to run. Look at RequisitionStepDefs.java for example.

Assign cucumber feature appropriate tag

Tags allow us to run different test cases in pipelines of different services. Look at the first line of RegularRequisitionTests.feature for example.

When tag is defined, it allows us to run: gradle clean cucumber -Ptags=@admin,@otherTag,@yetAnotherTag This will only run test cases that match the tags, nothing else.

Docker compose file

This docker compose file will be used by CI to link required containers together and run the tests. Look at docker-compose.requisition.yml for example.

Jenkins job

Job in both auth service and requisition service's pipelines, which uses the compose file defined in the previous step to run tests.

By doing this step, we can ensure that when either service's code changes, the test is ran. Look at OpenLMIS-requisition-contract-test

openlmis-contract-tests's People

Contributors

cuipengfei avatar mkwiatkowskisoldevelo avatar jkondrat avatar pgesek avatar yico-wheat avatar kpalkowska avatar sebbrudzinski avatar chunky56 avatar lukaslew avatar pbuzderewicz avatar joshzamor avatar pmironiuk avatar pmuchowski avatar eliasmu avatar krzysieksold avatar ngraczewski avatar brandonbowersox avatar magdatoczek avatar saleksandra avatar pawelcieszko avatar mikolajbassoldevelo avatar ellymakuba avatar mwedel avatar pnaw94 avatar oskarhinc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.