testin a method with request argument

Posted on 2006-05-09
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 27

    Expert Comment

    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

    >> 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

    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

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    communication with a non technical owner 16 96
    Run the project 5 79
    maven project import to eclipse problems 13 90
    maven set up 2 84
    PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
    Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now