• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

Junit4- struts2.0 -test Action class & DAO class

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can we write testclass( using JUnit4) to test Action class & DAO class in struts2.0 ? How?

Thanks.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. "How" depends on what, specifically, you're trying to test.
 
kedu par
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) My action class contain something like this

public String login()
{
Create object of DAO class(DAOref)
int temp=DAOref.validate(username,password);
if(temp==1)
{
return "ABC";
}
if(temp==2)
{
return "XYZ";
}
}



2) My DAO class coantain something like this

public int validate( String username, String password)
{
validate username & password with database & return corrosponding id;
return id;

}


How we can test above action class & DAO class?


 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Testing the action is trivial; use a mock DAO to provide the response you want.

How to test the DAO depends on what you actually want to test.
 
kedu par
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David Newton for your quick reply.

But still i am having one question..


I want to test username & password from DAO class(validate method)
I am having those values in login table database.
should I check those values in Test class by taking expected data as "hard coded" values? OR how?


Thanks....
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again--it depends on what you're trying to test. If you're trying to test the DAO's interaction with the database, that's a completely different issue (and not really a unit test, at least by my definition--that'd be an integration test). If you want to test your action, you don't *need* to go to the database--and for a unit test, I try to avoid database access because of the additional time overhead it would add.
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic