• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JUnit test cases problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
 
author & internet detective
Posts: 42173
937
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
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?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 42173
937
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

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.
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic