commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles Sadowski <gil...@harfang.homelinux.org>
Subject Re: [MATH] Change test code to remove fail("wrong exception type caught")
Date Fri, 01 Oct 2010 14:34:05 GMT
On Fri, Oct 01, 2010 at 03:17:58PM +0100, sebb wrote:
> There are quite a few test cases that have code like:
> 
> public void testSomething(){
>     try {
>       something();
>       fail("an exception should have been caught");
>     } catch (EstimationException ee) {
>       // expected behavior
>     } catch (Exception e) {
>       fail("wrong exception type caught");
>     }
> }
> 
> This is unnecessary code; worse, the actual Exception is lost.
> 
> I propose to fix these by converting them to:
> 
> public void testSomething() throws Exception {
>     try {
>       something();
>       fail("Expecting EstimationException ");
>     } catch (EstimationException ee) {
>       // expected behavior
> }
> 
> Any objections?

Shouldn't we move to JUnit 4, i.e. using
---CUT---
    @Test(expected=EstimationException.class)
    public void testSomething() {
        something();
    }
---CUT---

[Of course, this would force to split the test methods that currently
contain multiple statements that can throw an exception.]


Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message