Re: Obtaining server-side resource in suite() method using junit.textui.TestRunner

Kazuhito SUGURI <[email protected]>
Newsgroups gmane.comp.jakarta.cactus.user
Message-ID <[email protected]>
Hi Nicholas,

In article <CFF3C71613AD464B97B9BA232E24617203BB046F@msgusawmb01.ads.autodesk.com>,
Mon, 6 Mar 2006 11:29:01 -0800,
"Nicholas Dierauf" <[email protected]> wrote: 
nicholas> In order to set up a suite of tests to be executed client-side, I wish
nicholas> to access a server-side resource in my suite() method. This works fine
nicholas> when I run the test from my browser using ServletTestRunner, but I get a
nicholas> "java.lang.reflect.InvocationTargetException" when I attempt to run from
nicholas> a different jvm, ie with junit.textui.TestRunner. 
nicholas>  
nicholas> Is it possible to access server-side resources in the suite() method
nicholas> when executed from junit.textui.TestRunner?  (Please see below for some
nicholas> sample code.)

It may be possible, but I dont't recommend that way.
At least, you have to implement such mechanism by yourself.
Also, you have to take care for the server-side instantiation
which will be done without using suite() method.


nicholas> Here is the sample code. Some details have been left out for brevity. In
nicholas> this example, I want the test to run differently depending on the
nicholas> environment. Because the system property "servertype" is not defined in
nicholas> the textui JVM environment, I get the Exception.

You might pass the system property as a command-line argument of the JVM,
i.e. java -Dservertype=XXX junit.textui.TestRunner <class-name>.


nicholas> public MyTest(String environment) {
nicholas>   super("testSomething ");
nicholas>   this.environment = environment;
nicholas> }

Is this test really works with ServletTestRunner?
Have you ever test the value of this.environment in testSometing() method?

I think, the MyTest will be constructed with argument value of
"testSomething" for the second instantiateion in the servier-side.
So, this.environment above will have value of "testSomething"
that you are not expecting. I may misunderstanding something, though.


Hope this helps.
----
Kazuhito SUGURI
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.