Uploaded image for project: 'Clover'
  1. Clover
  2. CLOV-838

Support for Spring's @ExpectedException annotation

    • Icon: Suggestion Suggestion
    • Resolution: Fixed
    • 3.0
    • Reporting
    • None
    • Our product teams collect and evaluate feedback from a number of different sources. To learn more about how we use customer feedback in the planning process, check out our new feature policy.

      If you are using the @ExpectedAnnotation from spring, clover will report 0% code coverage and indicate the tests failed. e.g. the following test case will report no code coverage:

      @Test
      @ExpectedException(Exception.class)
      public void testApp() throws Exception
      {
           App a = new App();
           a.doStuff(); //a.doStuff throws an exception
      }

      Using the JUnit 4.x annotations works and the report will show the test passed and the code coverage will be reported correctly:

      @Test(expected = Exception.class)
      public void testApp() throws Exception
      {
           App a = new App();
           a.doStuff(); //a.doStuff throws an exception
      }

      Would be nice if clover could understand the spring annotations too.

            [CLOV-838] Support for Spring's @ExpectedException annotation

            Implemented in Clover 3.0

            Marek Parfianowicz added a comment - Implemented in Clover 3.0

            Sample project with JUnit4 and Spring annotations.

            Marek Parfianowicz added a comment - Sample project with JUnit4 and Spring annotations.

            Julien, please create a new issue or comment here with your code and we'll create one for you and we'll look into your problem. Yours is a separate problem to this so I'm closing this as implemented.

            Michael Studman (Inactive) added a comment - Julien, please create a new issue or comment here with your code and we'll create one for you and we'll look into your problem. Yours is a separate problem to this so I'm closing this as implemented.

            I've done a build of the other Maven Clover plugin that needs to be installed which you can grab here (as opposed to building it as mentioned above):

            http://downloads.atlassian.com/software/clover/downloads/maven-clover2-plugin-2.6.4-SNAPSHOT.jar
            http://downloads.atlassian.com/software/clover/downloads/maven-clover2-plugin-2.6.4-SNAPSHOT.pom

            Michael Studman (Inactive) added a comment - I've done a build of the other Maven Clover plugin that needs to be installed which you can grab here (as opposed to building it as mentioned above): http://downloads.atlassian.com/software/clover/downloads/maven-clover2-plugin-2.6.4-SNAPSHOT.jar http://downloads.atlassian.com/software/clover/downloads/maven-clover2-plugin-2.6.4-SNAPSHOT.pom

            Julien, I just re-read your initial comment and noticed you say @Test(expected=...) doesn't work for you (works fine in our tests). Please supply some sample code and we'll look into it.

            Michael Studman (Inactive) added a comment - - edited Julien, I just re-read your initial comment and noticed you say @Test(expected=...) doesn't work for you (works fine in our tests). Please supply some sample code and we'll look into it.

            BTW: The 0% coverage problem was by design. Clover, by default, will not count coverage of failed test cases. The method and class in question had only one statement which threw an exception hence 0% coverage.

            Michael Studman (Inactive) added a comment - BTW: The 0% coverage problem was by design. Clover, by default, will not count coverage of failed test cases. The method and class in question had only one statement which threw an exception hence 0% coverage.

            I of course meant change this in pom.xml:

            <cloverVersion>2.6.3</cloverVersion>
            

            to this:

            <cloverVersion>2.6.4-SNAPSHOT</cloverVersion>
            

            Michael Studman (Inactive) added a comment - I of course meant change this in pom.xml: <cloverVersion>2.6.3</cloverVersion> to this: <cloverVersion>2.6.4-SNAPSHOT</cloverVersion>

            Julien, Andi and Robert,

            I've created a snapshot version of clover core which addresses this issue.

            Please install this in your personal repository and try it out.
            http://downloads.atlassian.com/software/clover/downloads/clover-2.6.4-20100121.162448-1.pom.xml
            http://downloads.atlassian.com/software/clover/downloads/clover-2.6.4-20100121.162448-1.jar

            I achieved this through

            mvn install:install-file -DpomFile=/Users/michaelstudman/Downloads/clover-2.6.4-20100121.162448-1.pom.xml  -Dfile=/Users/michaelstudman/Downloads/clover-2.6.4-20100121.162448-1.jar
            

            I'm a bit of a Maven newbie, myself, so I had trouble verifying this but you may need to also install a version of maven-clover2-plugin with a dependency on the snapshot version of clover core. To do this, follow these instructions, change the maven-clover2-plugin's pom.xml to depend on the snapshot version of clover core (rather than 2.6.3) and then run maven clean install.

            http://confluence.atlassian.com/display/CLOVER/Clover+for+Maven+2+Developer+Guide

            Let us know how you go.

            Michael.

            PS: Special thanks to Robert for the test project.

            Michael Studman (Inactive) added a comment - Julien, Andi and Robert, I've created a snapshot version of clover core which addresses this issue. Please install this in your personal repository and try it out. http://downloads.atlassian.com/software/clover/downloads/clover-2.6.4-20100121.162448-1.pom.xml http://downloads.atlassian.com/software/clover/downloads/clover-2.6.4-20100121.162448-1.jar I achieved this through mvn install:install-file -DpomFile=/Users/michaelstudman/Downloads/clover-2.6.4-20100121.162448-1.pom.xml -Dfile=/Users/michaelstudman/Downloads/clover-2.6.4-20100121.162448-1.jar I'm a bit of a Maven newbie, myself, so I had trouble verifying this but you may need to also install a version of maven-clover2-plugin with a dependency on the snapshot version of clover core. To do this, follow these instructions, change the maven-clover2-plugin's pom.xml to depend on the snapshot version of clover core (rather than 2.6.3) and then run maven clean install. http://confluence.atlassian.com/display/CLOVER/Clover+for+Maven+2+Developer+Guide Let us know how you go. Michael. PS: Special thanks to Robert for the test project.

            That Clover reports the test failed is one problem (which we can understand why - internal implementation details). That it reports 0% coverage is another and is rather puzzling as that should't be the case. Investigating further...

            Michael Studman (Inactive) added a comment - That Clover reports the test failed is one problem (which we can understand why - internal implementation details). That it reports 0% coverage is another and is rather puzzling as that should't be the case. Investigating further...

            Hi,
            Anntoation @Test(expected=....class) ... didn't work for me.

            (I disagree the $Priority: Minor. So minor I can't use Clover.)

            Hope it will be fixed soon.

            Thanks.

            Julien Cornouiller added a comment - Hi, Anntoation @Test(expected=....class) ... didn't work for me. (I disagree the $Priority: Minor. So minor I can't use Clover.) Hope it will be fixed soon. Thanks.

              mstudman Michael Studman (Inactive)
              andrew.myers Andrew Myers [Atlassian]
              Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: