将TraderStoryRunner类的主体方法放进去,命名为Tc.java
import static org.junit.Assert.*; import java.util.List; import org.jbehave.core.embedder.Embedder; import org.jbehave.core.io.CodeLocations; import org.jbehave.core.io.StoryFinder; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import com.story.TestStories; import com.story.loginYahoo; public class Tc { @BeforeClass public static void setUpBeforeClass() throws Exception { } @AfterClass public static void tearDownAfterClass() throws Exception { } @Before public void setUp() throws Exception { } @After public void tearDown() throws Exception { } // @Test : 表示这是一个测试用例,只有标识了改符号的函数才会被执行测试 @Test public void runClasspathLoadedStoriesAsJUnit() { // Embedder defines the configuration and candidate steps Embedder embedder = new TestStories(); List<String> storyPaths = new StoryFinder().findPaths(CodeLocations.codeLocationFromClass(this.getClass()),"**/TestStories.story",""); // use StoryFinder to look up paths embedder.runStoriesAsPaths(storyPaths); } @Test public void runClasspathLoadedStories() { // Embedder defines the configuration and candidate steps Embedder embedder = new loginYahoo(); List<String> storyPaths = new StoryFinder().findPaths(CodeLocations.codeLocationFromClass(this.getClass()),"**/loginYahoo.story",""); // use StoryFinder to look up paths embedder.runStoriesAsPaths(storyPaths); } } |
至此,这个项目是可以运行起来了。
5.View Reports
点击运行上面的Tc.java类,可以得到:
Processing system properties {} Using controls EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=false,ignoreFailureInView=false,verboseFailures=false,verboseFiltering=false,storyTimeoutInSecs=300,threads=1] (BeforeStories) Running story com/story/TestStories.story Narrative: In order to show the browsing cart functionality As a user I want to browse in a gallery Browse Etsy.com (com/story/TestStories.story) Meta: @category browsing @color red Scenario: Browsing around the site for items ----------------------localhost Given I am on localhost ----------------------hello world !--Examples: !--|host|hello| !--|localhost|hello world| !--|www.baidu.com|hello baidu| Then print hello world !--Examples: !--|host|hello| !--|localhost|hello world| !--|www.baidu.com|hello baidu| (AfterStories) Generating reports view to 'C:\Program Files (x86)\Git\Jbehave\TestBehave_v2_testng\target\jbehave' using formats '[console, txt]' and view properties '{defaultFormats=stats, decorateNonHtml=true, viewDirectory=view, decorated=ftl/jbehave-report-decorated.ftl, reports=ftl/jbehave-reports-with-totals.ftl, maps=ftl/jbehave-maps.ftl, navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl}' Reports view generated with 0 stories (of which 0 pending) containing 0 scenarios (of which 0 pending) Processing system properties {} Using controls EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=false,ignoreFailureInView=false,verboseFailures=false,verboseFiltering=false,storyTimeoutInSecs=300,threads=1] (BeforeStories) Running story com/story/loginYahoo.story Narrative: In order to show the yahoo function As a user I want to login yahoo (com/story/loginYahoo.story) Scenario: normal login ++++++++++++++++++++++++++++++by.bouncer.login.yahoo.com Given yahoo login address by.bouncer.login.yahoo.com ++++++++++++++++++++++++++++++successful Then print successful (AfterStories) Generating reports view to 'C:\Program Files (x86)\Git\Jbehave\TestBehave_v2_testng\target\jbehave' using formats '[console, txt]' and view properties '{defaultFormats=stats, decorateNonHtml=true, viewDirectory=view, decorated=ftl/jbehave-report-decorated.ftl, reports=ftl/jbehave-reports-with-totals.ftl, maps=ftl/jbehave-maps.ftl, navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl}' Reports view generated with 0 stories (of which 0 pending) containing 0 scenarios (of which 0 pending) |
大体的思路,是将story和step对应起来,将story中的条件、参数传入step对应的类中,如果满足则通过测试,得到then给出的结果,否则得不到理想的结果。
相关文章: