Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there a way to model JUnit's Assume in Screenplay pattern? #2157

Closed
SiKing opened this issue Jul 8, 2020 · 8 comments
Closed

is there a way to model JUnit's Assume in Screenplay pattern? #2157

SiKing opened this issue Jul 8, 2020 · 8 comments

Comments

@SiKing
Copy link
Contributor

SiKing commented Jul 8, 2020

Something like actor.should(seeThat(actual, expected)) is essentially a JUnit Assert.

Is there a way to model JUnit's Assume? That is: if the actual does not match the expected, the test is marked as Ignored, not Failed.

I thought net.serenitybdd.screenplay.GivenWhenThen.seeIf() might be it, but I am sure if this is the correct way forward. I am not able to find any examples of using seeIf().

@wakaleo
Copy link
Member

wakaleo commented Jul 9, 2020

No, but it would be a good idea.

@globalworming
Copy link
Collaborator

globalworming commented Jul 9, 2020

There is something you can use already, http://thucydides.info/docs/articles/semantic-exceptions.html

actor.should(eventually(seeThat(actual, expected)).complainingWith(FailingAssumption.class))

while class FailingAssumption extends AssertionError implements CausesCompromisedTestFailure

@globalworming
Copy link
Collaborator

globalworming commented Jul 9, 2020

also.. shouldn't it be easy to write an interaction like actor.attemptsTo(TestAssumption(actual, expected)) and then implement Assume in the performAs method?

@ricardorlg-aval
Copy link

Other option that I use, is the Facts, u can make a Fact about something and in case it doesn’t satisfy the rule, throw a compromised exception or use the Junit assume inside the setUp method of the fact.

@SiKing
Copy link
Contributor Author

SiKing commented Jul 9, 2020

There is something you can use already, http://thucydides.info/docs/articles/semantic-exceptions.html
...
while class FailingAssumption extends TestCompromisedException

This seemed like the easiest solution, but I get:

The method orComplainWith(Class<? extends Error>) in the type Consequence<WebElementState> is not applicable for the arguments (Class<FailingAssumption>)

I also tried extends org.junit.AssumptionViolatedException but that gave me the same error.

@SiKing
Copy link
Contributor Author

SiKing commented Jul 9, 2020

Other option that I use, is the Facts, u can make a Fact about something and in case it doesn’t satisfy the rule, throw a compromised exception or use the Junit assume inside the setUp method of the fact.

@ricardorlg-aval I have never used Fact and I am having a hard time finding any examples of this. Could you provide some more details?

@globalworming
Copy link
Collaborator

globalworming commented Jul 9, 2020

Correction on my example:

class FailingAssumption extends AssertionError implements CausesCompromisedTestFailure

@SiKing
Copy link
Contributor Author

SiKing commented Jul 9, 2020

That builds, but the test gets marked as Failed. I need it marked as Skipped.

I ended up doing something like: Assume.assumeThat(valueOf(target).answeredBy(actor), containsOnlyText("text"));, which is one refactor away from your TestAssumption(actual, expected) suggestion.

@wakaleo wakaleo closed this as completed Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants