Skip to content

Instantly share code, notes, and snippets.

@picpromusic
Last active December 18, 2015 02:09
Show Gist options
  • Save picpromusic/5709019 to your computer and use it in GitHub Desktop.
Save picpromusic/5709019 to your computer and use it in GitHub Desktop.
JBehave Scopes

DI-Scopes for JBehave at scenario- and storylevel

Sometimes scopes in JBehave-based tests of configured injections are different to the original application configurations. Let's say we have a webapplication that configures some injections as a session-based scope. If we now want to test parts of the application without a real servlet context we sometimes need a diffrent scope for some of theses injections. Usefull scopes in jbehave-based tests are scenario- and story-scopes. Naturally we can use @Before/After-Scenario/Story Annotations to handle the the reset manually, but it is much easier and cleaner to write such things as

bind(Interface.class).to(Implementation.class).in(JBehaveScopes.SCENARIO);

You can investigate an example here : ServletWithScopeTest.java

The example uses this Story and Steps to show how Scenario-Scopes can work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment