Unit-testing with JUnit throws NullPointerException for Controllers

995 views
Skip to first unread message

Justin

unread,
May 31, 2011, 8:07:30 AM5/31/11
to play-framework, j...@kakao.com
Hello.

I am a new-bee to Play. As you know, it is a wonderful framework.
But, there's a small problem that irritates me.

I tried to test methods of Controllers. And an exception was thrown
when I called the method in my JUnit test function.
Interestingly, there was no exception when calling Controller methods
of which return type is not 'void'.

As you know, the return types of methods of Controllers are mostly
'void'.

Do you have any idea?

Maigx liN

unread,
May 31, 2011, 8:26:09 AM5/31/11
to play-fr...@googlegroups.com
what exception

2011/5/31 Justin <ppa...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


Julien Tournay

unread,
May 31, 2011, 9:22:57 AM5/31/11
to play-fr...@googlegroups.com
How do you "call" those methods ?
--
Real Programmers don't need comments-- the code is obvious.

Justin

unread,
Jun 2, 2011, 5:46:34 AM6/2/11
to play-framework
Thanks for your concerns, Maigx and Julien.

The trace failure list is following:
java.lang.NullPointerException
at play.classloading.enhancers.ControllersEnhancer
$ControllerInstrumentation.isActionCallAllowed(ControllersEnhancer.java:
183)
at
controllers.CsTransferController.transfer(CsTransferController.java)
at CsTest.testTransferCoupons(CsTest.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod
$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:
15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:
41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:
20)
at play.test.PlayJUnitRunner$StartPlay
$1$1$1.execute(PlayJUnitRunner.java:73)
at play.Invoker$Invocation.run(Invoker.java:265)
at play.Invoker.invokeInThread(Invoker.java:67)
at play.test.PlayJUnitRunner$StartPlay
$1$1.evaluate(PlayJUnitRunner.java:68)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
76)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at play.test.PlayJUnitRunner.run(PlayJUnitRunner.java:48)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:
49)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:
390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:
197)


Julien,
I called a method from a UnitTest-inherited class like below:

public class CsTest extends UnitTest {
...
@Test
public void testTransferCoupons() throws
SecurityException, NoSuchMethodException,
IllegalAccessException, InvocationTargetException
{
CsTransferController.transfer(...); //
CsTransferController is a child-class of Controller
....
}

Thanks.
Reply all
Reply to author
Forward
0 new messages