testin a method with request argument

Posted on 2006-05-09
Medium Priority
Last Modified: 2010-04-01
Good Morning Experts,
i have a method that take Request as argument:validate(String myQueryString, HttpServletRequest request)

Is there a way to test this independantly before even trying to use in a sevlet?
Question by:komlaaa
LVL 28

Expert Comment

ID: 16640525
Maybe just a little easier would be for you to test your method in a JSP.  

    public yourReturnType validate(String myQueryString, HttpServletRequest request) {
                                                                                                                              //body of your method

     //You can call your method in a scriptlet or in an expression.
LVL 19

Accepted Solution

actonwang earned 500 total points
ID: 16641501
>> test this independantly before even trying to use in a sevlet?
      not sure what is in your method, but try to extract the logic out of it to make it unit testable.
      for example, you have the code as:
      String param1= (String)request.getParameter("param1");

      // Use it next

       then try to create a testable method as:
       public void validateUserName(String myQueryString,String param1,...)

       test it in your unit test package so that you can run it as often as you can.


Author Comment

ID: 16687361
that was good idea.
I first test a simple string e.g validate( String queryString ) and then in my servlet i did something like

String str = request.getQueryString();

Good idea.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What happened when I tried to make my phone, a Samsung Galaxy S8, stop dropping all WiFi signals was a saga I won't repeat here, but what you might want to know is how it started and how I got it working again.
The article explains the process to deploy a Self-Service password reset portal I developed a few years ago. Hopefully, it will prove useful to someone.  Any comments, bug reports etc. are welcome...
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question