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 Dinesh N <gn...@india.com> on 2004/02/09 08:05:59 UTC

Assesrtion Failed Error while JSP Testing

Hi Friends,
    I am new to this technology. I am testing a jsp page which do some operation on java compiled class.

Now i have created some test case like:

public void teststringArray3()
	{
		 System.out.println("Value is "+session.getServletContext().getAttribute("stringArray3Count"));
		 assertSame("This should be same","1",session.getServletContext().getAttribute("stringArray3Count"));
		
	}

****stringArray3Count is an veriable which is set to proper value in JSP Page.

But i am not able to access the Value in Test class. It is returning NULL. CAn anybody help me...?
Please let me know where is problem in my Code or what..?

I also tried with. pageContext.include("/test.jsp");
and then pageContext.getAttribute(stringArray3Count());
But still it returns null.

After running the Result is:

   This should be same expected same:<1> was not:<null>

junit.framework.AssertionFailedError: This should be same expected same:<1> was not:<null>
at:
arraytest.StringArrayJSPTest.teststringArray3

CAn anybody tell me what is the problem ?

Thanking You,

Ragards,
Dinesh N.

-- 
India.com free e-mail - www.india.com. 
Check out our value-added Premium features, such as an extra 20MB for mail storage, POP3, e-mail forwarding, and ads-free mailboxes!

Powered by Outblaze

Re: Assesrtion Failed Error while JSP Testing

Posted by "J. B. Rainsberger" <jb...@rogers.com>.
Dinesh N wrote:

> Hi Friends,
>     I am new to this technology. I am testing a jsp page which do some operation on java compiled class.
> 
> Now i have created some test case like:
> 
> public void teststringArray3()
> 	{
> 		 System.out.println("Value is "+session.getServletContext().getAttribute("stringArray3Count"));


> 		 assertSame("This should be same","1",session.getServletContext().getAttribute("stringArray3Count"));

Don't use assertSame() here, anyway: there is no way that the servlet 
context will return the same String object as the literal string "1". 
Use assertEquals() instead.

As for why the servlet context attribute has a null value, we need to 
see more code, such as the code that puts "stringArray3Count" in the 
servlet context in the first place.
-- 
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

Re: Assesrtion Failed Error while JSP Testing

Posted by Kazuhito SUGURI <su...@lab.ntt.co.jp>.
Hi Dinesh,

In article <20...@ws5-7.us4.outblaze.com>,
Mon, 09 Feb 2004 15:05:59 +0800,
"Dinesh N" <gn...@india.com> wrote: 
gnavsupe> I am new to this technology. I am testing a jsp page which do some operation on java compiled class.
gnavsupe> 
gnavsupe> Now i have created some test case like:
gnavsupe> 
gnavsupe> public void teststringArray3()
gnavsupe> 	{
gnavsupe> 		 System.out.println("Value is "+session.getServletContext().getAttribute("stringArray3Count"));
gnavsupe> 		 assertSame("This should be same","1",session.getServletContext().getAttribute("stringArray3Count"));
gnavsupe> 		
gnavsupe> 	}

It should have pageContext.include("/test.jsp"), as you had tried.
Also, you should use assertEquals, as Rainsberger noticed.

gnavsupe> I also tried with. pageContext.include("/test.jsp");
gnavsupe> and then pageContext.getAttribute(stringArray3Count());
gnavsupe> But still it returns null.

I believe that the stringArray3Count() should be "stringArray3Count".


In article <20...@ws5-8.us4.outblaze.com>,
Tue, 10 Feb 2004 15:09:37 +0800,
"Dinesh N" <gn...@india.com> wrote: 
gnavsupe>           I will give you  my JSP which i want to test.
gnavsupe> It is:
gnavsupe>   <%@page import="com.arraytest.StringArray"%>

I wrote (and tested) a sample JSP with JspTestCase.
It uses java.lang.String for attributes, however,
I believe that you can find out what you have to do
for your com.arraytest.StringArray.

I hope this will helps you.
----
Kazuhito SUGURI
mailto:suguri.kazuhito@lab.ntt.co.jp

RE: Assesrtion Failed Error while JSP Testing

Posted by Vincent Massol <vm...@pivolis.com>.
Hi Dinesh,

Can you please show us your test case? The teststringArray3() method
does not call anything that sets your stringArrya3Count attribute in the
servlet context. Where is that set?

Thanks
-Vincent

> -----Original Message-----
> From: Dinesh N [mailto:gnavsupe@india.com]
> Sent: 09 February 2004 08:06
> To: cactus-user@jakarta.apache.org
> Subject: Assesrtion Failed Error while JSP Testing
> 
> Hi Friends,
>     I am new to this technology. I am testing a jsp page which do some
> operation on java compiled class.
> 
> Now i have created some test case like:
> 
> public void teststringArray3()
> 	{
> 		 System.out.println("Value is
> "+session.getServletContext().getAttribute("stringArray3Count"));
> 		 assertSame("This should be
>
same","1",session.getServletContext().getAttribute("stringArray3Count"))
;
> 
> 	}
> 
> ****stringArray3Count is an veriable which is set to proper value in
JSP
> Page.
> 
> But i am not able to access the Value in Test class. It is returning
NULL.
> CAn anybody help me...?
> Please let me know where is problem in my Code or what..?
> 
> I also tried with. pageContext.include("/test.jsp");
> and then pageContext.getAttribute(stringArray3Count());
> But still it returns null.
> 
> After running the Result is:
> 
>    This should be same expected same:<1> was not:<null>
> 
> junit.framework.AssertionFailedError: This should be same expected
> same:<1> was not:<null>
> at:
> arraytest.StringArrayJSPTest.teststringArray3
> 
> CAn anybody tell me what is the problem ?
> 
> Thanking You,
> 
> Ragards,
> Dinesh N.
> 
> --
> India.com free e-mail - www.india.com.
> Check out our value-added Premium features, such as an extra 20MB for
mail
> storage, POP3, e-mail forwarding, and ads-free mailboxes!
> 
> Powered by Outblaze
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org