General discussion

Locked

Junit testcase

By kusumadas ·
Hi...

Am new to junit testing...i have some doubts pls..help me...
i want to write Test Case based on functionality for login module
Values are present in database i.e.oracle 9i

how to write testcase for this

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

You have doubts about junit testing?

by seanferd In reply to Junit testcase

Not sure what you're ... wait. <i>Unit</i> testing? As in application development?

Regardless, I'm not sure what kind of advice can be offered if you don't understand the basics. Your request is <i>very</i> broad. Could you narrow it down to a specific problem?

Collapse -

Junit testcase

by kusumadas In reply to You have doubts about jun ...

private String loginId="admin";
private String loginPassword="admin1234";


@Test
public void testGetLoginId() {
assertEquals("admin",this.loginId);

}
@Test
public void testGetLoginPassword() {
assertEquals("admin1234",this.loginPassword);
}


My doubt is...In my application login values are taking from database
How to write test cases for this

Collapse -

Junit testcase

by kusumadas In reply to Junit testcase

i know basics...even i hve written testcases also ..by giving assumed values

public static void main(String args[])
{
try
{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter username:");
String Username=br.readLine();
System.out.println("Enter Password:");
String Password=br.readLine();
if (Username.equals("admin") && Password.equals("admin123"))
{
System.out.println("Correct");
} else
{
System.out.println("Not Matching");
}
}
catch (Exception e){}
My doubt is...In my application login values are taking from database
How to write test cases for this

Collapse -

Junit testcase

by kusumadas In reply to Junit testcase

private String loginId="admin";
private String loginPassword="admin1234";


@Test
public void testGetLoginId() {
assertEquals("admin",this.loginId);

}
@Test
public void testGetLoginPassword() {
assertEquals("admin1234",this.loginPassword);
}

Collapse -

Can't say from here

by Tony Hopkinson In reply to Junit testcase

depends on how your code is organised and what you are testing.

The ideal would be
one piece of code that queried the db for the data.
Testing that would involve having a "test" database available with some known values in.
Generally you'd do a setup routine to insert some test data, run the tests, then tear down (delet the test values.
The point being that it doesn't matter what the data is as such, just that your sql is right and you've covered the obvious bases, like reporting it's not there.

In terms of the code that needs the login data, well it doesn't care where it comes from. A nice way of doing it, is to write an Interface. In live code that's implemented by get from db, in test it you just return some hard coded values.

If the details are then used to login to another system then you need some know values to test that you are logging right, any test after that you are testing another application, which is something you should not do in a unit test.

If your code is just one big splodge, of get this and do that with it, then while you might be using Junit, you aren't unit testing.

Collapse -

Junit testcase

by kusumadas In reply to Can't say from here

Thank u so much :)

Back to IT Employment Forum
6 total posts (Page 1 of 1)  

Related Forums