public
Last active

Sample conversion of a basic JUnit test to one using Narrative

  • Download Gist
gistfile1.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
// 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());
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.