You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Jean-Charles Giardina <jc...@gmail.com> on 2006/11/22 16:26:29 UTC

Can I pass parameters to ServletTestCase ?

Hi,

Can I pass URL parameters to a ServletTestCase ?
I want to test more and more value with the same test method.
I don't want to recompile to change value.

I want to use an URL like :
  http://localhost/ServletTestRunner?suite=my.tests.MyTest&foo=bar
where "foo" is the parameter name and "bar" is the parameter value.

Thks

Re: Can I pass parameters to ServletTestCase ?

Posted by Franz Roth <fr...@gmx.de>.
Hi,

I think all should be fine documented at the cactus project-page, somtimes  
somone says: read the f* manual, well here's a simple sample:


import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.cactus.ServletTestCase;
import org.apache.cactus.WebRequest;
import org.apache.cactus.WebResponse;
import org.apache.log4j.Logger;

import **.**.FRLoggerFactory;

public class TestSimple extends ServletTestCase {
	
	private Logger _log;
	public void beginTest(WebRequest theRequest) {
		_log= FRLoggerFactory.getLog();
		_log.info("beginTest");
		theRequest.addParameter("test", "value");
	}
	public void testTest() {
		try {
			TestServlet writer= new TestServlet();
			writer.init(config);
			writer.doPost(request, response);
		}
		catch (Exception e) {
			_log.error("", e);
		}
	}
	public void endTest(WebResponse theResponse) {
		String[] result= theResponse.getTextAsArray();
		_log.debug("and here's the result:");
		for (int i = 0; i < result.length; i++) {
			_log.debug(result[i]);
		}
		
	}
	class TestServlet extends HttpServlet {
		private static final long serialVersionUID = 1L;

		protected void doPost(HttpServletRequest req,
				HttpServletResponse resp) {
			Logger log= FRLoggerFactory.getLog();
			log.debug("got a param: " + req.getParameter("test"));
			try {
				PrintWriter out= resp.getWriter();
				out.println("<html>\n" +
						"<head><title>TestSimle</title>\n" +
						"</head>\n" +
						"<body><h3>All is fine done ...</h3>\n" +
						"</body></html>");
			}
			catch(Exception e) {
				log.error("", e);
			}
		}
	}
}



Am 22.11.2006, 16:26 Uhr, schrieb Jean-Charles Giardina  
<jc...@gmail.com>:

> Hi,
>
> Can I pass URL parameters to a ServletTestCase ?
> I want to test more and more value with the same test method.
> I don't want to recompile to change value.
>
> I want to use an URL like :
>   http://localhost/ServletTestRunner?suite=my.tests.MyTest&foo=bar
> where "foo" is the parameter name and "bar" is the parameter value.
>
> Thks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org



-- 
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/

Re: Can I pass parameters to ServletTestCase ?

Posted by Shay Thompson <st...@adobe.com>.
Can you be a bit more specific on what the problem is you're having with 
running tests via the command line?  I run tons of tests using Cactus, 
all from the command-line using Ant.  
http://jakarta.apache.org/cactus/integration/ant/task_cactus.html



Dan.Doyle@cexp.com wrote:
> If you are interested in passing parameters, take a look at this page,
> http://jakarta.apache.org/cactus/writing/howto_testcase.html, under Step
> 6. I haven't actually used this functionality.
>
> I am still having a problem running cactus tests from a JUnit
> TestRunner. The only test runner I can use at this point is
> ServletTestRunner. So, it is not looking like Cactus will be used if I
> can't resolve the problem of running cactus tests from the command line.
>
> I think this forum is sort of dead.
>
> Hope that helps,
> Dan
>
> -----Original Message-----
> From: Jean-Charles Giardina [mailto:jc.giardina@gmail.com] 
> Sent: Wednesday, November 22, 2006 8:26 AM
> To: Cactus User
> Subject: Can I pass parameters to ServletTestCase ?
>
> Hi,
>
> Can I pass URL parameters to a ServletTestCase ?
> I want to test more and more value with the same test method.
> I don't want to recompile to change value.
>
> I want to use an URL like :
>   http://localhost/ServletTestRunner?suite=my.tests.MyTest&foo=bar
> where "foo" is the parameter name and "bar" is the parameter value.
>
> Thks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>
>
>   

-- 

If you apply Ohms Law, e=mc2, to the hypotenuse and add to that a catalyst consisting of a set of struts and a gigahertz, you will theoretically arrive at an answer yesterday...

Shay Thompson - Lead Computer Scientist
Adobe Systems, Inc. - Titan Core QE 
Voice: x34728 or 612.251.5415


Re: Can I pass parameters to ServletTestCase ?

Posted by Shay Thompson <st...@adobe.com>.
If you use the Ant integration of Cactus you can run multiple tests 
which all generate a standard JUnit test report.  You can then just 
convert those reports to HTML to view all the packages.



david.j.novogrodsky@accenture.com wrote:
> Here is a question I have for the list.
>  
> I am running several Cactus tests using the default ServletTestRunner. I want a break-down of the test run by which package they are in. The XSLT and default ServletTestRunner only allows one package on the command line.
>  
> How can I cycle through several packages of tests and collect the results into one output document?
>  
>
> David Novogrodsky
>
>
> This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information.  If you have received it in error, please notify the sender immediately and delete the original.  Any other use of the email by you is prohibited.
>
>   
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org

-- 

If you apply Ohms Law, e=mc2, to the hypotenuse and add to that a catalyst consisting of a set of struts and a gigahertz, you will theoretically arrive at an answer yesterday...

Shay Thompson - Lead Computer Scientist
Adobe Systems, Inc. - Titan Core QE 
Voice: x34728 or 612.251.5415


RE: Can I pass parameters to ServletTestCase ?

Posted by da...@accenture.com.
Here is a question I have for the list.
 
I am running several Cactus tests using the default ServletTestRunner. I want a break-down of the test run by which package they are in. The XSLT and default ServletTestRunner only allows one package on the command line.
 
How can I cycle through several packages of tests and collect the results into one output document?
 

David Novogrodsky


This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information.  If you have received it in error, please notify the sender immediately and delete the original.  Any other use of the email by you is prohibited.

Re: Can I pass parameters to ServletTestCase ?

Posted by Shay Thompson <st...@adobe.com>.
This has been the best solution that we've found for getting parameters 
with Server Side tests.

Nicholas Dierauf wrote:
> I believe that you would have to modify the ServletTestRunner servlet in order to accept parameters.
>  
> You may want to look into writing a data-driven test instead. When I need configurable test like this, I add a suite() method to the Cactus test to read from a configuration file, such as an XML file. You can then iterate through the configuration file and generate a test case for each item. This way you can just modify the configuration file instead of updating and recompiling the java file every time you want to add a new test case. J.B. Rainsberger's JUnit Recipes has a great chapter on writing data-driven tests.
>  
> Good luck,
> Nick.
>  
>
> 	-----Original Message----- 
> 	From: Dan.Doyle@cexp.com [mailto:Dan.Doyle@cexp.com] 
> 	Sent: Wed 11/22/2006 8:13 AM 
> 	To: cactus-user@jakarta.apache.org 
> 	Cc: 
> 	Subject: RE: Can I pass parameters to ServletTestCase ?
> 	
> 	
>
> 	If you are interested in passing parameters, take a look at this page,
> 	http://jakarta.apache.org/cactus/writing/howto_testcase.html, under Step
> 	6. I haven't actually used this functionality.
> 	
> 	I am still having a problem running cactus tests from a JUnit
> 	TestRunner. The only test runner I can use at this point is
> 	ServletTestRunner. So, it is not looking like Cactus will be used if I
> 	can't resolve the problem of running cactus tests from the command line.
> 	
> 	I think this forum is sort of dead.
> 	
> 	Hope that helps,
> 	Dan
> 	
> 	-----Original Message-----
> 	From: Jean-Charles Giardina [mailto:jc.giardina@gmail.com]
> 	Sent: Wednesday, November 22, 2006 8:26 AM
> 	To: Cactus User
> 	Subject: Can I pass parameters to ServletTestCase ?
> 	
> 	Hi,
> 	
> 	Can I pass URL parameters to a ServletTestCase ?
> 	I want to test more and more value with the same test method.
> 	I don't want to recompile to change value.
> 	
> 	I want to use an URL like :
> 	  http://localhost/ServletTestRunner?suite=my.tests.MyTest&foo=bar
> 	where "foo" is the parameter name and "bar" is the parameter value.
> 	
> 	Thks
> 	
> 	---------------------------------------------------------------------
> 	To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> 	For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 	
> 	
> 	---------------------------------------------------------------------
> 	To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> 	For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 	
> 	
>
>   

-- 

If you apply Ohms Law, e=mc2, to the hypotenuse and add to that a catalyst consisting of a set of struts and a gigahertz, you will theoretically arrive at an answer yesterday...

Shay Thompson - Lead Computer Scientist
Adobe Systems, Inc. - Titan Core QE 
Voice: x34728 or 612.251.5415


RE: Can I pass parameters to ServletTestCase ?

Posted by Nicholas Dierauf <ni...@autodesk.com>.
I believe that you would have to modify the ServletTestRunner servlet in order to accept parameters.
 
You may want to look into writing a data-driven test instead. When I need configurable test like this, I add a suite() method to the Cactus test to read from a configuration file, such as an XML file. You can then iterate through the configuration file and generate a test case for each item. This way you can just modify the configuration file instead of updating and recompiling the java file every time you want to add a new test case. J.B. Rainsberger's JUnit Recipes has a great chapter on writing data-driven tests.
 
Good luck,
Nick.
 

	-----Original Message----- 
	From: Dan.Doyle@cexp.com [mailto:Dan.Doyle@cexp.com] 
	Sent: Wed 11/22/2006 8:13 AM 
	To: cactus-user@jakarta.apache.org 
	Cc: 
	Subject: RE: Can I pass parameters to ServletTestCase ?
	
	

	If you are interested in passing parameters, take a look at this page,
	http://jakarta.apache.org/cactus/writing/howto_testcase.html, under Step
	6. I haven't actually used this functionality.
	
	I am still having a problem running cactus tests from a JUnit
	TestRunner. The only test runner I can use at this point is
	ServletTestRunner. So, it is not looking like Cactus will be used if I
	can't resolve the problem of running cactus tests from the command line.
	
	I think this forum is sort of dead.
	
	Hope that helps,
	Dan
	
	-----Original Message-----
	From: Jean-Charles Giardina [mailto:jc.giardina@gmail.com]
	Sent: Wednesday, November 22, 2006 8:26 AM
	To: Cactus User
	Subject: Can I pass parameters to ServletTestCase ?
	
	Hi,
	
	Can I pass URL parameters to a ServletTestCase ?
	I want to test more and more value with the same test method.
	I don't want to recompile to change value.
	
	I want to use an URL like :
	  http://localhost/ServletTestRunner?suite=my.tests.MyTest&foo=bar
	where "foo" is the parameter name and "bar" is the parameter value.
	
	Thks
	
	---------------------------------------------------------------------
	To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
	For additional commands, e-mail: cactus-user-help@jakarta.apache.org
	
	
	---------------------------------------------------------------------
	To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
	For additional commands, e-mail: cactus-user-help@jakarta.apache.org
	
	


RE: Can I pass parameters to ServletTestCase ?

Posted by Da...@cexp.com.
If you are interested in passing parameters, take a look at this page,
http://jakarta.apache.org/cactus/writing/howto_testcase.html, under Step
6. I haven't actually used this functionality.

I am still having a problem running cactus tests from a JUnit
TestRunner. The only test runner I can use at this point is
ServletTestRunner. So, it is not looking like Cactus will be used if I
can't resolve the problem of running cactus tests from the command line.

I think this forum is sort of dead.

Hope that helps,
Dan

-----Original Message-----
From: Jean-Charles Giardina [mailto:jc.giardina@gmail.com] 
Sent: Wednesday, November 22, 2006 8:26 AM
To: Cactus User
Subject: Can I pass parameters to ServletTestCase ?

Hi,

Can I pass URL parameters to a ServletTestCase ?
I want to test more and more value with the same test method.
I don't want to recompile to change value.

I want to use an URL like :
  http://localhost/ServletTestRunner?suite=my.tests.MyTest&foo=bar
where "foo" is the parameter name and "bar" is the parameter value.

Thks

---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-user-help@jakarta.apache.org