junit4: New Method Proposal: ExpectedException#expect(Throwable, Callable)
Many times I needed to assert a block of code in test-method to throw an exception, and check how the throwing block has changed values. I had to use try-catch.
So I would like to implement new method with such of signature ExpectedException#expect(Throwable, Callable)
.
Usage:
Object obj = expect( Exception.class , new Callable() { ..do and return something.. });
Usage of Lambda in Java 8:
expect( Exception.class , () -> { ..do and return something.. } )
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 20 (18 by maintainers)
I was just wishing for the same! How about:
Note that unlike @Tibor17, I’m suggesting a third argument that allows for adding additional checks on the
Exception
. I.e. we would have the following signatures:Note also that neither
Callable
norRunnable
are really suited for this use-case. Neither of them allows for throwingThrowable