Filtering with multiple metafilters in JBehave

烈酒焚心 提交于 2019-12-12 09:19:40

问题


Situation:

In my current project we are running all kinds of different JBehave stories. Every ".story" file is related to a product and a flow.

Example:
xyz-cellphone-call.story would be the story describing making a phonecall with a cellphone.
xyz-phone-call.story would be the story describing making a phonecall with a fixed-line phone.
xyz-cellphone-browse.story would be the story describing browsing the internet with a cellphone.

My question: In Jbehave you can add metaFilters to filter on the stories based on meta tags. Assume the tags are @product & @action. (@product cellphone, @action call).
Would it be possible to pass a filter to run the JBehave stories concerning both the phone & cellphone stories, if yes, what would be the syntax?

I've tried adding the following filters (none of which work):

+product cellphone +product phone
+product cellphone|phone
+product cellphone,phone

Same for actions.

Is it possible to filter on multiple meta-tags?


回答1:


Yes it is possible. In the API docs you will find this information:

A filter is uniquely identified by its String representation which is parsed and matched by the MetaFilter.MetaMatcher to determine if the Meta is allowed or not.

The MetaFilter.DefaultMetaMatcher interprets the filter as a sequence of any name-value properties (separated by a space), prefixed by "+" for inclusion and "-" for exclusion. E.g.:

MetaFilter filter = new MetaFilter("+author Mauro -theme smoke testing +map *API -skip"); filter.allow(new Meta(asList("map someAPI")));

The use of the MetaFilter.GroovyMetaMatcher is triggered by the prefix "groovy:" and allows the filter to be interpreted as a Groovy expression.

MetaFilter filter = new MetaFilter("groovy: (a == '11' | a == '22') && b == '33'");

So probably if you play with the conditions, you will get your run configuration customized. Try this example:

mvn clean install -P -Djbehave.meta.filter="myCustomRunConf:(+product && +action)"

More info amout the MetaFilter class in the API docs: http://jbehave.org/reference/stable/javadoc/core/org/jbehave/core/embedder/MetaFilter.html




回答2:


I guess there is easier solution for you using groovy http://jbehave.org/reference/stable/meta-filtering.html

In your case it would be -Dmetafilter="groovy: "product=='cellphone' && action=='call'"

I tried it as "-Dmetafilter=groovy:t2 && t3" for this feature file

Meta:
    @t1

Narrative:
    As a user
    I want to blah-blah-blah


Scenario: test 1
Meta:
    @t2

Given I am on home page


Scenario: test 2
Meta:
    @t2
    @t3

Given I am on home page


Scenario: test 3
Meta:
    @t3

Given I am on home page

Only test 2 scenario is executed in this case




回答3:


How about:

mvn clean install -P -Djbehave.meta.filter = "+product cellphone&&phone"


来源:https://stackoverflow.com/questions/11742151/filtering-with-multiple-metafilters-in-jbehave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!