Details
Description
The following unit test class will pass successfully when run as a Groovy Script, outside of the grails environment:
class SampleTests extends GroovyTestCase {
void testSomething()
{ def constString = "world"; def javaString = 'hello ' + constString; def gString = "hello $constString"; assertEquals(javaString, gString); }}
new SampleTests().testSomething()
//End Script
A similar unit test, when run in the grails environment (grails -test-app) will fail with the following AssertionError:
java.lang.AssertionError: expected: java.lang.String<hello world> but was: org.codehaus.groovy.runtime.GStringImpl<hello world>
This same scenario, when run in Grails 1.3.7, passes as expected. I've attached a zip file that contains a vanilla grails project, with a single groovy class: test/unit/SampleTests.groovy
Note that if the statement:
assert javaString == gString
is used, the test passes in grails.
-
Hide
- assertEqualsTestCaseProject.zip
- 25/Apr/12 5:54 AM
- 228 kB
- Jerry Duffy
-
- assertEqualsTestCaseProject/.classpath 0.7 kB
- assertEqualsTestCaseProject/.project 0.5 kB
- assertEqualsTestCaseProject/.../org.codehaus.groovy.eclipse.preferences.prefs 0.1 kB
- assertEqualsTestCaseProject/application.properties 0.2 kB
- assertEqualsTestCaseProject/.../ApplicationResources.groovy 0.1 kB
- assertEqualsTestCaseProject/.../BootStrap.groovy 0.1 kB
- assertEqualsTestCaseProject/.../BuildConfig.groovy 2 kB
- assertEqualsTestCaseProject/.../Config.groovy 4 kB
- assertEqualsTestCaseProject/.../DataSource.groovy 1 kB
- assertEqualsTestCaseProject/.../resources.groovy 0.0 kB
- assertEqualsTestCaseProject/.../UrlMappings.groovy 0.2 kB
- assertEqualsTestCaseProject/.../messages.properties 3 kB
- assertEqualsTestCaseProject/.../messages_cs_CZ.properties 3 kB
- assertEqualsTestCaseProject/.../messages_da.properties 3 kB
- assertEqualsTestCaseProject/.../messages_de.properties 4 kB
- assertEqualsTestCaseProject/.../messages_es.properties 3 kB
- assertEqualsTestCaseProject/.../messages_fr.properties 2 kB
- assertEqualsTestCaseProject/.../messages_it.properties 2 kB
- assertEqualsTestCaseProject/.../messages_ja.properties 4 kB
- assertEqualsTestCaseProject/.../messages_nl.properties 3 kB
- assertEqualsTestCaseProject/.../messages_pt_BR.properties 3 kB
- assertEqualsTestCaseProject/.../messages_pt_PT.properties 3 kB
- assertEqualsTestCaseProject/.../messages_ru.properties 4 kB
- assertEqualsTestCaseProject/.../messages_sv.properties 3 kB
- assertEqualsTestCaseProject/.../messages_th.properties 6 kB
- assertEqualsTestCaseProject/.../messages_zh_CN.properties 2 kB
- assertEqualsTestCaseProject/.../error.gsp 0.3 kB
- assertEqualsTestCaseProject/.../index.gsp 3 kB
- assertEqualsTestCaseProject/.../main.gsp 2 kB
- assertEqualsTestCaseProject/stacktrace.log 90 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
I believe this is because of the "import static org.junit.Assert.*" that is added by GrailsTestCompiler.
We may be dispatching to the wrong method.
This test fails:
This test passes:
The first example is dispatching to org.junit.Assert.assertEquals.