Quantcast

Controller test

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Controller test

Quantumuniverses
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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Controller test

OverZealous
Probably because you imported the wrong class?

java.lang.ClassNotFoundException: com.ExampleController

Maybe you meant

import com.test.ExampleController

- Phil

QuantumUniverses wrote:
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
...

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Controller test

ideasculptor
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.
 


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
<a href="tel:2012%2005%2010%2017" value="+12012051017" target="_blank">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



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Controller test

Jeff Brown-3
In reply to this post by Quantumuniverses
May 10, 2012 10:57 AM
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




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/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Controller test

Quantumuniverses
In reply to this post by OverZealous
My controller is here:
 
com.ExampleController
 
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? Sorpresa
 
 
"Phil DeJarnett" <[hidden email]> ha scritto nel messaggio news:[hidden email]...
Probably because you imported the wrong class?
 
java.lang.ClassNotFoundException: com.ExampleController
 
Maybe you meant
 
import com.test.ExampleController
 
- Phil
 
QuantumUniverses wrote:
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
...
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Controller test

Quantumuniverses
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


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Controller test

Quantumuniverses
In reply to this post by Jeff Brown-3
This let my test work:
 
public ExampleControllerTests() {
    super(com.ExampleController)
}
 
Thanks a lot!
 
 
"Jeff Brown" <[hidden email]> ha scritto nel messaggio news:[hidden email]...
May 10, 2012 10:57 AM
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




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/
Loading...