Site icon TestingDocs.com

Filtering stories with Meta Filters

Introduction

In this post, we will discuss filtering stories with meta filters with a simple example. When we have a bunch of stories and we want only some stories to run based on meta-information. In this example, we will see how to filter stories from within code.

Meta Information

For example, we have 2 stories with different meta information marked as P1 and P2 as shown below:

StoryOne is p1

Meta:
@P1

StoryTwo is p2

Meta:
@P2

Meta Filters

However, we want to run only one story which is marked with priority P1. JBehave supports meta tags so that you can mark some set of tests as P1 tests. Also, we can instruct JBehave to run the tests, include/exclude only the P1 tests. Furthermore, we can do this in many ways. In this post, we will see how to perform this from within the code.

Using the below filter would run only the tests marked as P1.

metaFilters={“+P1”}

 

Sample code listing

@RunWith(value=AnnotatedEmbedderRunner.class) 
@UsingEmbedder(embedder=Embedder.class,
               metaFilters={"+P1"}
                )

 

 

When we run the stories, we can see that one story file is excluded by the meta filter as shown below:

 

 

Open the results folder we notice that the story marked as P1 has run and the other story got excluded and has not run.

 

In the next post, we will see how to filter stories using JBehave maven plugin.

 

JBehave Tutorials on this website can be found at:
https://www.testingdocs.com/jbehave-framework-tutorial/

For more details on the JBehave framework, visit the official JBehave website at:
http://jbehave.org

Exit mobile version