I have parametrized test with 2 variants:
From this value is depends one assert:
- In case
NULLit should be checked if object has
- In case
NOT NULLit should be checked if object has
As I mentioned (see xUnit Tests Patterns ) using conditional statements in assert is anti-pattern.
How can I solve this problem properly?
I am trying at the moment to apply Guard assertion pattern:
if-assertion is splitted into 2 assertions
At the beginning there is test parameter check (
NOT NULL) with guard assertion:
it('case describing conditionalParamter=NOT NULL'): expect(conditionalParamter, 'to be a', 'string') // Guard assertion which can FAIL test. Is it OK? Can I simply **SKIP** assertion WITHOUT test failing expect(myStub.args, 'to satisfy', [[ nonConditionalParamter, ExpressionWhichUsesNonNullConditionalParamterValue ]]) it('case describing conditionalParamter= NULL') expect(conditionalParamter, 'to be falsy') // Guard assertion. The same issue expect(myStub.args, 'to satisfy', [[ nonConditionalParamter, ExpressionForNullConditionalParamterValue ]])
But in this case we have 2 failed assertions. Is it appropriate solution?
Is there better ways to solve problem?