I tried this morning, but it still have the same NullPointerException. It seems that the begin method is called after the setUp method (messages printed in the begin method never appear in the console). I believed it is the contrary, isn't it ?

Romain


Kazuhito SUGURI a écrit :

Hi Romain,

In article <[EMAIL PROTECTED]>,
Tue, 02 Aug 2005 15:44:57 +0200,
Romain Thouvenin <[EMAIL PROTECTED]> wrote: rthouvenin> I'm creating a tool to launch tests based on cactus. rthouvenin> It uses my own test cases which extend ServletTestCase, and these rthouvenin> testCases have a field used in test methods. rthouvenin> But when i launch the test and try to access this field in the setUp rthouvenin> method, i get a NullPointerException. rthouvenin> I've checked with prints and with a debugger, the field is correctly rthouvenin> initialized.
(snip)
rthouvenin> To build the TestSuite, i use my own constructor with a code like 
this :
rthouvenin> # suite.addTest(new MyTestCase("testName", MyClass param));
rthouvenin> and a field of MyTestCase is directly set with param.

Server side test-case construction of Cacuts uses
constructor with one String argument ... or use the default
(i.e. no argument) constructor and setName method to specify
test method name to be executed.
So, your custom constructor is ignored in server-side.


If the parameter is determined at client-side in run-time,
you might use request parameter to pass it to server.
For example:
   private Param param;
   public ExampleTestCase(String name) {
       super(name);
   }
   public ExampleTestCase(String name, Param param) {
       this(name);
       this.param = param;
   }
   public void begin(WebRequest request) {
       request.addParameter("PARAM_NAME_FOR_TESTCASE", param.toString(),
                            WebRequest.POST_METHOD);
   }
   public void setUp() {
       String paramStr = request.getParameter("PARAM_NAME_FOR_TESTCASE");
       this.param = new Param(paramStr);
   }
   public void testXXX() {
       ....
   }

Just an idea.

Hope this helps,
----
Kazuhito SUGURI





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to