Git Product home page Git Product logo

hitchstory's Introduction

HitchStory

HitchStory is a python 3 testing and living documentation framework for building easily maintained example driven executable specifications (sometimes dubbed acceptance tests).

It was designed initially to make realistic testing of code less of a goddamn chore so the tests would actually get written and run.

The executable specifications can be written to specify and test applications at any level and have been used successfully to replace traditional low level unit tests, integration tests and end to end tests with easier to maintain tests.

The specifications are written using StrictYAML and the code to execute them is written by you, in python.

Example

example.story:

Logged in:
  given:
    website: /login  # preconditions
  steps:
  - Form filled:
      username: AzureDiamond
      password: hunter2
  - Clicked: login


Email sent:
  about: |
    The most basic email with no subject, cc or bcc
    set.
  based on: logged in             # inherits from and continues from test above
  steps:
  - Clicked: new email
  - Form filled:
      to: [email protected]
      contents: |                # long form text
        Hey guys,

        I think I got hacked!
  - Clicked: send email
  - Email was sent

engine.py:

from hitchstory import BaseEngine, GivenDefinition, GivenProperty
from mockemailchecker import email_was_sent
from mockselenium import Webdriver
from strictyaml import Str

class Engine(BaseEngine):
    given_definition = GivenDefinition(
        website=GivenProperty(Str()),
    )

    def set_up(self):
        self.driver = Webdriver()
        self.driver.visit(
            "http://localhost:5000{0}".format(self.given['website'])
        )

    def form_filled(self, **textboxes):
        for name, contents in sorted(textboxes.items()):
            self.driver.fill_form(name, contents)

    def clicked(self, name):
        self.driver.click(name)

    def email_was_sent(self):
        email_was_sent()
from hitchstory import StoryCollection
from pathquery import pathquery
from engine import Engine

StoryCollection(pathquery(".").ext("story"), Engine()).named("Email sent").play()

Will output:

RUNNING Email sent in /path/to/example.story ...
Visiting http://localhost:5000/login
Entering text hunter2 in password
Entering text AzureDiamond in username
Clicking on login
Clicking on new email
In contents entering text:
Hey guys,

I think I got hacked!


Entering text [email protected] in to
Clicking on send email
Email was sent
SUCCESS in 0.1 seconds.

Installation and set up

You can install hitchstory through pypi in any python 3 virtualenv:

$ pip install hitchstory

However, it's recommended to install and set up hitchstory with hitchkey, which will take care of automatically setting up a up the recommended hitchstory environment.

Either install hitchkey with pipsi:

pipsi install hitchkey

Or, if you'd prefer, you can safely install with "sudo pip":

sudo pip install hitchkey

Once hitchkey is installed:

Example demo of hitchstory basics:

cd temp
hk --demo hitchstory ; hk bdd email

Example python API test demo (uses game of life):

cd temp
hk --demo pythonapi ; cd pythonapi ; hk bdd

Using HitchStory

Approach to using HitchStory

Best practices, how the tool was meant to be used, etc.

Design decisions and principles

Somewhat controversial design decisions are justified here.

Why not X instead?

There are several tools you can use instead, this is why you should use this one instead:

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.