jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kazuhito SUGURI <suguri.kazuh...@lab.ntt.co.jp>
Subject Re: bug with double instance ?
Date Tue, 02 Aug 2005 15:36:35 GMT
Hi Romain,

In article <42EF78D9.5070402@sfwan.com>,
Tue, 02 Aug 2005 15:44:57 +0200,
Romain Thouvenin <rthouvenin@sfwan.com> 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

Mime
View raw message