0

I am trying to expect an assertion failure and then the set of all my tests should not throw a failure.

/**
* @expectedException Exception
*
*/
public function testGetAtlantisDriver(){

    $object = null
    $this->assertNotNull($object);

}

But this is not working.

What I get is an assertion failure

Failed asserting that null is not null.

I expected the tests would be pass without failure. What did I wrong or what can I do to make this pass?

Thank you

1 Answer 1

3

The @expectedException annotation is used when your code is supposed to throw an exception. This does not include the PHPUnit assertion errors. You can't expect an assertion failure.

If it worked the way you suggest there would be problems: Suppose you have a test method with some assertions and then some code that throws an exception with an @expectedException. Then if some of the assertions failed you would not know, as the test would still pass.

You can't make a test pass if an assertion is not right, and that's what is expected from a testing Framework.

You can only mark a test as skipped with

$this->markSkipped("reason for skipping");

if you want to temporarily disable a test.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.