issue with object oriented programming
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.entrySe开发者_StackOverflow中文版t();
Iterator itr = set.iterator();
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";
}
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.
精彩评论