• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

junit newbie

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

i'am newbie in junit, i work in a web application using jsf and icefaces, actually there are no source code in order to use a database.
And all what i have are javabeans, the faces-config descriptor and the jspx pages, all run fine.
my question is what kind of methods i will test by junit, because i have only void methods or methods which return a finally static string "outcoms".
testing setters is it usefull?
in a web application what we test? only the source code (javabeans and other classes)? or we can test the gui too, because i think there are tools to test gui i don't know if it's usefull for me.

Best reguards.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jad,
You can unit test a void method. What does it do? Presumably it sets values in a bean or calls an EJB/data access method/etc. This is testable.

You can test through the GUI as well. See the testing FAQ at the top of this forum form some tools.
 
samantha clarkson
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
i don't know what to do with methods like the example below :

public String submit(){
if(this.id!=0){
submit_update();
}
else
{
submit_add();
}
return "goListCategory";
}

the id is an attribute of the category class.
the "goListCategory" is an outcome which references to the jspx page displaying all categories.
All what i suggest is :


public class CategoryTest {

private Category firstCat;
private Category secondCat;
public void setUp() throws Exception {
firstCat = new Category(0,"something","something);
secondCat = new Category(12,"something","something");
}
public void testSubmit() {
assertEquals("The submit method had an error !!","goListCategory",firstCat.submit());
}
}

any suggestion ! :roll:
Thanks

[ September 26, 2008: Message edited by: jad igor ]
[ September 26, 2008: Message edited by: jad igor ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this case, the desired behavior for submit() is (apparently) to "add" or "update" depending on whether the object has a non-zero ID or not.

So that's what we test for, right?

One approach could be to write two tests: One to make sure that submit() invokes submit_add() when the object doesn't yet have an ID and another to make sure that it invokes submit_update() when it does.
[ September 26, 2008: Message edited by: Lasse Koskela ]
 
samantha clarkson
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i've discovered another problem.

in my class category, i have an attribute :
private ArrayList dsnames = DataSourceManager.getInstance().getDsnames();

As you saw before i declared an instance of category which execute the code line below. i have an exception null pointer dsnames.

i didn't understand why this exception, if i run the project in tomcat all work.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is just guesswork but is DataSourceManager#getDsnames() possibly trying to fetch something from the JNDI tree or some configuration file? If that's the case, then your development environment is probably missing those configurations.
reply
    Bookmark Topic Watch Topic
  • New Topic