Package: hitchstory
HitchStoryType-safeStrictYAMLpython integration testing framework. With this
framework, your tests can:Rewrite themselves from program output (command line test example)Autogenerate documentation (website test example)The tests can be run on their own or as pytest tests.Demo projects with demo testsProjectStorytestsPython codeDoc templateAutogenerated docsWebsiteadd todo,correct spellingengine.pydocstory.ymlAdd todo,Correct my spellingREST APIadd todo,correct spellingengine.pydocstory.ymlAdd todo,Correct my spellingInteractive command line appadd todo,correct spellingtest_integration.pydocstory.ymlAdd todo,Correct my spellingA Python APIadd todo,correct spellingtest_integration.pydocstory.ymlAdd todo,Correct my spellingCode Exampleexample.story:Logged in:given:website:/login# preconditionssteps:-Form filled:username:AzureDiamondpassword:hunter2-Clicked:loginEmail sent:about:|The most basic email with no subject, cc or bccset.based on:logged in# inherits from and continues from test abovefollowing steps:-Clicked:new email-Form filled:to:Cthon98@aol.comcontents:|# long form textHey guys,I think I got hacked!-Clicked:send email-Email was sentengine.py:fromhitchstoryimportBaseEngine,GivenDefinition,GivenPropertyfromhitchstoryimportFailure,strings_matchfromstrictyamlimportStrclassEngine(BaseEngine):given_definition=GivenDefinition(website=GivenProperty(Str()),)def__init__(self,rewrite=False):self._rewrite=rewritedefset_up(self):print(f"Load web page at{self.given['website']}")defform_filled(self,**textboxes):forname,contentsinsorted(textboxes.items()):print(f"Put{contents}in name")defclicked(self,name):print(f"Click on{name}")deffailing_step(self):raiseFailure("This was not supposed to happen")deferror_message_displayed(self,expected_message):"""Demonstrates steps that can rewrite themselves."""actual_message="error message!"try:strings_match(expected_message,actual_message)exceptFailure:ifself._rewrite:self.current_step.rewrite("expected_message").to(actual_message)else:raisedefemail_was_sent(self):print("Check email was sent!")>>>fromhitchstoryimportStoryCollection>>>frompathlibimportPath>>>fromengineimportEngine>>>>>>StoryCollection(Path(".").glob("*.story"),Engine()).named("Email sent").play()RUNNINGEmailsentin/path/to/working/example.story...Loadwebpageat/loginPuthunter2innamePutAzureDiamondinnameClickonloginClickonnewemailPutHeyguys,IthinkIgothacked!innamePutCthon98@aol.cominnameClickonsendemailCheckemailwassent!SUCCESSin0.1seconds.Install$pipinstallhitchstoryCommunityHelp is available if you ask questions in these places:Github discussions|Github issues(not just for bugs) |Slack channelUsing HitchStoryEvery feature of this library is documented and listed below.
It is tested and documented with itself.Using HitchStory: With PytestIf you already have pytest set up, you can quickly and easily write
a test using hitchstory that runs alongside your other pytest tests:Self rewriting tests with pytest and hitchstoryUsing HitchStory: EngineHow to use the different features of the story engine:Hiding stacktraces for expected exceptionsGiven preconditionsGradual typing of story stepsMatch two JSON snippetsMatch two strings and show diff on failureExtra story metadata - e.g. adding JIRA ticket numbers to storiesStory with parametersStory that rewrites given preconditionsStory that rewrites itselfStory that rewrites the sub key of an argumentRaising a Failure exception to conceal the stacktraceArguments to stepsStrong typingUsing HitchStory: Documentation GenerationHow to autogenerate documentation from your tests:Generate documentation with extra variables and functionsGenerate documentation from storyUsing HitchStory: InheritanceInheriting stories from each other:Inherit one story from another simplyStory inheritance - given mapping preconditions overriddenStory inheritance - override given scalar preconditionsStory inheritance - parametersStory inheritance - stepsVariationsUsing HitchStory: RunnerRunning the stories in different ways:Continue on failure when playing multiple storiesFlaky story detectionPlay multiple stories in sequenceRun one story in collectionShortcut lookup for story namesApproach to using HitchStoryBest practices, how the tool was meant to be used, etc.Is HitchStory a BDD tool? How do I do BDD with hitchstory?Complementary toolsDomain Appropriate Scenario Language (DASL)Executable specificationsFlaky TestsThe Hermetic End to End Testing PatternANTIPATTERN - Analysts writing stories for the developerSnapshot Test Driven Development (STDD)Test Artefact Environment IsolationTest concern leakageTests as an investmentWhat is the difference betweeen a test and a story?The importance of test realismTesting non-deterministic codeSpecification Documentation Test TrialityDesign decisions and principlesDesign decisions are justified here:Declarative User StoriesWhy does hitchstory mandate the use of given but not when and then?Why is inheritance a feature of hitchstory stories?Why does hitchstory not have an opinion on what counts as interesting to "the business"?Why does hitchstory not have a command line interface?PrinciplesWhy does HitchStory have no CLI runner - only a pure python API?Why Rewritable Test Driven Development (RTDD)?Why does HitchStory use StrictYAML?Why not X instead?HitchStory is not the only integration testing framework.
This is how it compares with the others:Why use Hitchstory instead of Behave, Lettuce or Cucumber (Gherkin)?Why not use the Robot Framework?Why use hitchstory instead of a unit testing framework?Using HitchStory: Setup on its ownIf you want to use HitchStory without pytest:Creating a basic command line test runnerUsing HitchStory: BehaviorMiscellaneous docs about behavior of the framework:Abort a story with ctrl-CUpgrade breaking changes between v0.14 and v0.15Handling failing testsRunning a single named story successfully