|
I launched this test but it failed: why?
package com.test.unit import com.ExampleController class ExampleControllerTests extends ControllerUnitTestCase { protected void setUp() { } protected void tearDown() { } void testActionIndex() { } } RESULT: Running test com.Example.test.ExampleControllerTests... testActionIndex...FAILED 2012 05 10 17:47:05 ERROR grails.util.GrailsUtil.sanitize (GrailsUtil.java:260) - Sanitizing stacktrace: java.lang.ClassNotFoundException: com.ExampleController ... --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Probably because you imported the wrong class?
Maybe you meant import com.test.ExampleController - Phil QuantumUniverses wrote:
|
|
In reply to this post by Quantumuniverses
On Thu, May 10, 2012 at 8:57 AM, QuantumUniverses <[hidden email]> wrote: I launched this test but it failed: why? Because the class com.ExampleController isn't in your classpath, apparently. You'd have to provide some kind of context if you want a response that goes beyond reiterating what the exception has to say. If you don't have a com.ExampleController class, then remove that import statement.
|
|
In reply to this post by Quantumuniverses
I wouldn't expect that test to compile because ControllerUnitTestCase is in the grails.test package, which isn't imported. It looks like your test is not in the same package as the controller that it is testing. If that is what you want, then you need to write a constructor and pass the controller under test as an argument to super()... package com.test.unit class ExampleControllerTests extends grails.test.ControllerUnitTestCase { public ExampleControllerTests() { super(com.ExampleController) } protected void setUp() { } protected void tearDown() { } void testActionIndex() { } } The error message says that com.ExampleController cannot be found. I would expect it to say com.test.unit.ExampleController cannot be found. The combination of those problems makes me wonder if maybe you tried 2 or 3 different things and the error message above is not related to the version of the test above. With Grails 2.0.3, this does work... $ cat test/unit/com/test/unit/ExampleControllerTests.groovy package com.test.unit class ExampleControllerTests extends grails.test.ControllerUnitTestCase { public ExampleControllerTests() { super(com.ExampleController) } protected void setUp() {} protected void tearDown() {} void testActionIndex() {} } $ $ grails test-app unit: | Completed 1 unit test, 0 failed in 103ms | Tests PASSED - view reports in target/test-reports HTH jb --
Jeff Brown SpringSource http://www.springsource.com/ Autism Strikes 1 in 166 Find The Cause ~ Find The Cure http://www.autismspeaks.org/ |
|
In reply to this post by OverZealous
My controller is here:
Why should I import this?
com.test.unit.ExampleController
In other words: have I to import my real controller (com.ExampleController)
or a unit test controller?
"Phil DeJarnett" <[hidden email]> ha scritto nel messaggio
news:[hidden email]... Probably because you imported the wrong class?
Maybe you meant
import
com.test.ExampleController
- Phil
QuantumUniverses wrote:
|
|
In reply to this post by Quantumuniverses
If ExampleControllerTests extends GrailsUnitTestCase (instead of
ControllerUnitTestCase) then it doesn't fail. But I should extend ControllerUnitTestCase to mock my controller.. right? "QuantumUniverses" ha scritto nel messaggio news:jogogg$tv7$[hidden email]... I launched this test but it failed: why? package com.test.unit import com.ExampleController class ExampleControllerTests extends ControllerUnitTestCase { protected void setUp() { } protected void tearDown() { } void testActionIndex() { } } RESULT: Running test com.Example.test.ExampleControllerTests... testActionIndex...FAILED 2012 05 10 17:47:05 ERROR grails.util.GrailsUtil.sanitize (GrailsUtil.java:260) - Sanitizing stacktrace: java.lang.ClassNotFoundException: com.ExampleController ... --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by Jeff Brown-3
This let my test work:
super(com.ExampleController) } Thanks a lot!
"Jeff Brown" <[hidden email]> ha scritto nel messaggio
news:[hidden email]...
I wouldn't expect that test to compile because ControllerUnitTestCase is in the grails.test package, which isn't imported. It looks like your test is not in the same package as the controller that it is testing. If that is what you want, then you need to write a constructor and pass the controller under test as an argument to super()... package com.test.unit class ExampleControllerTests extends grails.test.ControllerUnitTestCase { public ExampleControllerTests() { super(com.ExampleController) } protected void setUp() { } protected void tearDown() { } void testActionIndex() { } } The error message says that com.ExampleController cannot be found. I would expect it to say com.test.unit.ExampleController cannot be found. The combination of those problems makes me wonder if maybe you tried 2 or 3 different things and the error message above is not related to the version of the test above. With Grails 2.0.3, this does work... $ cat test/unit/com/test/unit/ExampleControllerTests.groovy package com.test.unit class ExampleControllerTests extends grails.test.ControllerUnitTestCase { public ExampleControllerTests() { super(com.ExampleController) } protected void setUp() {} protected void tearDown() {} void testActionIndex() {} } $ $ grails test-app unit: | Completed 1 unit test, 0 failed in 103ms | Tests PASSED - view reports in target/test-reports HTH jb -- Jeff Brown SpringSource http://www.springsource.com/ Autism Strikes 1 in 166 Find The Cause ~ Find The Cure http://www.autismspeaks.org/ |
| Powered by Nabble | Edit this page |
