Skip to content

Instantly share code, notes, and snippets.

@elefevre
Created November 6, 2010 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elefevre/665399 to your computer and use it in GitHub Desktop.
Save elefevre/665399 to your computer and use it in GitHub Desktop.
Sample conversion of a basic JUnit test to one using Narrative
// our existing test
@Test
public void shouldLinkToStrategySourceCodeWithLinkBackToPaperSelectedPage() throws IOException {
getBackTestStore().storeStrategy(QUANT, ENDED_SOLUTION_ID, ZipUtils.zip("import com.algodeal.marketrunner.strategies.*;\n @Instruments(futures=com.algodeal.marketData.instruments.Futures.CAC_40)\npublic class MyStrategy extends AbstractStrategy {}", "MyStrategy.java"));
beginAtAsQuant("/users/paperTradeSolution.do?solutionId=" + ENDED_SOLUTION_ID + "&paperTrading=true"); // clicks on link executing javascript
beginAtAsQuant("/users/backtestHistory.html");
clickLinkWithText("Show only", 1);
assertThat(getSolutionHtml(ENDED_SOLUTION_ID)).contains("<a href=\"/users/editStrategy.html?solutionId=" + ENDED_SOLUTION_ID + "&backUrl=/users/backtestHistory.html%3Fpage=1%26filter=PAPER\">");
}
// with Narrative
@Test
public void shouldLinkToStrategySourceCodeWithLinkBackToPaperSelectedPage() throws IOException {
Given.the(quant).was_able_to(postStrategy(ENDED_SOLUTION_ID)) //
.was_able_to(startPaperModeOnThatStrategy()) //
.was_able_to(visitPage("backtest history"));
When.the(quant).attempts_to(viewOnlyPaperTradedStrategies());
Then.the(quant).expects_that(strategy(ENDED_SOLUTION_ID)).should_be(displayed());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment