Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JUnit test cases problem

 
Pooja Gadre
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this thread to the Testing Forum.

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

Mark
 
Pooja Gadre
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic