Grails

Patch: Build Fails to Run All Tests

Details

  • Type: Test Test
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0, 1.0.1
  • Fix Version/s: 1.0.2
  • Component/s: ContinuousBuild, Testing
  • Labels:
    None
  • Environment:
    Mac OS X 10.5.1, JDK 5
  • Patch Submitted:
    Yes

Description

The current Grails build script only runs tests where the class name ends in "Tests". See ant/build/unit-test.xml.

<include name="**/${test}Tests.class" />

The build excludes the several tests whose class name ends in "Test". The attached patch corrects that issue, first by updating ant/build/unit-test.xml.

<include name="**/${test}Test.class" />
<include name="**/${test}Tests.class" />

Also, Grails currently includes some classes that are not technically tests, but they still end in "Test". For example, test/persistence/org/codehaus/groovy/grails/domain/ManyToManyTest.groovy is a sample domain class used to support other test cases. This class has no test cases of its own. This patch renames that class to SampleManyToMany.groovy. Doing so prevents JUnit from looking for tests in that class (since it's not even intended to include test cases). Without that change, JUnit will expect the class to include at least one test, and it will report an error otherwise.

Grails currently includes a handful of these "sample" classes that needed to be renamed. This patch renames those classes accordingly.

The patch improves the Grails build by:

  1. Ensuring that all test cases are run with every build!
  2. Improving the code coverage (since the missing tests are now part of the build).

Regarding code coverage, here's a quick example of how these missing tests were resulting in inaccurate code coverage.

Look at #getFormatFromURI in the latest Grails build. Observe that it lacks proper coverage. However, if you look at #testGetFormatFromURI in WebUtilsTest.groovy, you can see that it provides the missing coverage. Because the current Grails build excludes this test, the coverage report wrongly reports this line as lacking coverage. This patch corrects that problem and many similar problems.

Activity

Hide
Jason Rudolph added a comment -

Corrected link to current coverage report for WebUtils.java.

Show
Jason Rudolph added a comment - Corrected link to current coverage report for WebUtils.java.
Hide
Peter Ledbrook added a comment -

Should we not rename the tests so that they match the convention? Also, I would consider removing ManyToManyTest since the useful code appears to be commented out. In general though, I think the rename is a good idea. BTW, SampleUnitOneToMany.groovy should be SampleUniOneToMany.groovy.

Show
Peter Ledbrook added a comment - Should we not rename the tests so that they match the convention? Also, I would consider removing ManyToManyTest since the useful code appears to be commented out. In general though, I think the rename is a good idea. BTW, SampleUnitOneToMany.groovy should be SampleUniOneToMany.groovy.
Hide
Jason Rudolph added a comment -

Hi Peter,
I agree that the tests should follow a consistent naming convention. I'd consider that to be a superior enhancement. If the team agrees, I'm happy to submit a patch that makes that change instead of updating ant/build/unit-test.xml.

Cheers,
Jason

Show
Jason Rudolph added a comment - Hi Peter, I agree that the tests should follow a consistent naming convention. I'd consider that to be a superior enhancement. If the team agrees, I'm happy to submit a patch that makes that change instead of updating ant/build/unit-test.xml. Cheers, Jason
Hide
Graeme Rocher added a comment -

Agreed this would be a better patch

Show
Graeme Rocher added a comment - Agreed this would be a better patch
Hide
Graeme Rocher added a comment -

In the meantime i've renamed WebUtilsTest (ie added the s)

Show
Graeme Rocher added a comment - In the meantime i've renamed WebUtilsTest (ie added the s)
Hide
Jason Rudolph added a comment -

Thanks, Graeme. I'll put together an updated patch and post it here.

Show
Jason Rudolph added a comment - Thanks, Graeme. I'll put together an updated patch and post it here.
Hide
Jason Rudolph added a comment -

The updated patch renames the remaining test classes ending in "Test" to instead end in "Tests", thus making all Grails test classes follow a consistent naming convention.

test/persistence/org/codehaus/groovy/grails/orm/hibernate/cfg/GrailsDomainConfigurationUtilTest.java
test/commons/org/codehaus/groovy/grails/validation/routines/RegexValidatorTest.java
test/commons/org/codehaus/groovy/grails/validation/routines/UrlValidatorTest.java
test/commons/org/codehaus/groovy/grails/validation/routines/InetAddressValidatorTest.java
test/commons/org/codehaus/groovy/grails/validation/routines/DomainValidatorTest.java

The patch no longer modifies the build script (as the renaming process above removes the need to change the build script).

Show
Jason Rudolph added a comment - The updated patch renames the remaining test classes ending in "Test" to instead end in "Tests", thus making all Grails test classes follow a consistent naming convention. test/persistence/org/codehaus/groovy/grails/orm/hibernate/cfg/GrailsDomainConfigurationUtilTest.java test/commons/org/codehaus/groovy/grails/validation/routines/RegexValidatorTest.java test/commons/org/codehaus/groovy/grails/validation/routines/UrlValidatorTest.java test/commons/org/codehaus/groovy/grails/validation/routines/InetAddressValidatorTest.java test/commons/org/codehaus/groovy/grails/validation/routines/DomainValidatorTest.java The patch no longer modifies the build script (as the renaming process above removes the need to change the build script).
Hide
Graeme Rocher added a comment -

Thanks for the patch!

Show
Graeme Rocher added a comment - Thanks for the patch!
Hide
Graeme Rocher added a comment -

Bulk closing bunch of resolved issues

Show
Graeme Rocher added a comment - Bulk closing bunch of resolved issues

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: