-1

hi I am new to java. I have to write test case for this method in java,

public class ABC{
public void updateUser(String emailId, HashMap hm) {
        String updateKey = createUniqueUserKey(emailId);
        int noOfColumn = (UserColumnFamily.getColumnNames()).size();
        Set set = hm.entrySet();
        Iterator itr = set.iterator();
swarup7m
  • 183
  • 1
  • 2
  • 12
  • 1
    I might like to suggest not shoving all your closing brackets on one line: it'll make adding new methods hard, it'll make adding `else` branches hard, it'll make appending code after the `for` statement hard, etc. – sarnold Feb 01 '11 at 09:18

2 Answers2

1

First, I would look up generics. This will enable you to avoid all the dynamic typing (i.e. your casts to String and Map.Entry).

Second, I would recommend using a testing framework such as JUnit. This gives you an Assert class that allows you to make calls like

@Test
public void myTestMethod {
  // Some operation
  Assert.assertEquals("This is printed if the assertion fails", 
                      expectedValue, testedValue);
}

But if you can't use JUnit then enable Java assertions with the -ea flag and do something like:

public void myTestMethod {
  // Some operation
  assert expectedValue == testedValue : "This is printed if the assertion fails";
}
0

I'm assuming you want to use a unit testing framework? In which case, I'd recommend JUnit - here's a very simple tutorial:

JUnit Tutorial

The assert() methods are just a check to see if a value is what you'd expect it to be (or not). So most of the values in the test case will only make sense to you / your usage.

Michael
  • 7,348
  • 10
  • 49
  • 86