This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Testing and the fly likes JUnit test cases problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit test cases problem" Watch "JUnit test cases problem" New topic
Author

JUnit test cases problem

Pooja Gadre
Greenhorn

Joined: Mar 19, 2011
Posts: 2
[size=12]Hello,
I m new to JUnit and i donot know how to write test cases to test code.
I m also finding it difficut to test the DB operations.
Is the server on which the project is usually run , supposed to be started when i want to run the Junit test cases?
And cant we write DB operations testing in Junit? instead of dbunit?

Please help!!

Code which is not running is as follows:

public class SimpleJdbcUserDAOTest {
SimpleJdbcUserDAO usrdao;
static final String name="@ron";
final User user=new User(name,"abcxyz","What?","Yes","1");


@Test
public void testInsert() {
int i=usrdao.insert(user);

assertEquals("Should not accept special characters!", i, 0);
}
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

Welcome to CodeRanch!

Pooja Gadre wrote:Is the server on which the project is usually run , supposed to be started when i want to run the Junit test cases?

Only if you are trying to test on the server, say with a remote call. It is valid to test without the server to test the database code. We do this here on JForum.

Pooja Gadre wrote:And cant we write DB operations testing in Junit? instead of dbunit?

Of course. DBUnit sits on top of JUnit to make database loads easier.

What error are you getting with that code?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Moving this thread to the Testing Forum.

This is the Spring Framework forum and there isn't a Spring question here. Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Pooja Gadre
Greenhorn

Joined: Mar 19, 2011
Posts: 2
hey hello there..

Thanks for replying..


I don't know from which module to start testing.

Right now i m giving sample data to test units. but when i run the test case using the option "run as junit test case" in Springsource Tool Suite (STS), i am not getting the expected result. my application is connected to the database and a web server. So is it necessary to keep running the server in the background to make the test case show a green signal?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

Pooja Gadre wrote:, i am not getting the expected result.

We are going to need more information about why it isn't working to give you a helpful reply. Are you getting a database error? Is it pointing to the wrong database? Are you getting some other exception? See TellTheDetails for more tips on giving helpful information to people who can give advice.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JUnit test cases problem
 
Similar Threads
how to write and run junit test cases in eclipse?
How to mock Hibernate Session?
NX: What functions to submit
Application Testing tools and tests
JUnit Testing