Multiple test cases for a single method
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   satish_kumar
Posted On:   Thursday, May 5, 2005 05:36 PM

What are the methodologies which are followed when someone wants to test a method in a class in different ways by passing different parameters(positive and Negative testcases)? I have a method call validate(String a) in a class named Validator. If I want to write a test class for this, I create a class called TestValidator and then write a method named testValidate(). Now I want to call the Validate method by passing a Valid String, an Invalid String etc. Should I need to write 2 mehtods like testValidate1 and testValidate2 or are there any other methodologies for achieving this? I was thinking about a switch block, but need to know if this is an industry followed methodology. I think this should be a common p   More>>

What are the methodologies which are followed when someone wants to test a method in a class in different ways by passing different parameters(positive and Negative testcases)?




I have a method call validate(String a) in a class named Validator. If I want to write a test class for this, I create a class called TestValidator and then write a method named testValidate(). Now I want to call the Validate method by passing a Valid String, an Invalid String etc. Should I need to write 2 mehtods like testValidate1 and testValidate2 or are there any other methodologies for achieving this? I was thinking about a switch block, but need to know if this is an industry followed methodology.




I think this should be a common problem for anybody who is using JUnit. But I didn't get much information when I searched for the same.




Can somebody help me out.







Thanks in Advance.

   <<Less

Re: Multiple test cases for a single method

Posted By:   Anonymous  
Posted On:   Friday, May 6, 2005 04:39 AM

Your Validate class is your test object and you have several testcases to fully test one of your test objects method. That´s not unusual...

public class CalculatorTest {
public void testMultiplicity1() {
assertEquals(calculator.multiply(2, 2), 4);
}
public void testMultiplicity2() {
assertEquals(calculator.multiply(-2, -2), 4);
}
public void testMultiplicity31() {
assertEquals(calculator.multiply(-2, 2), -4);
}

public void testMultiplicity4() {
assertEquals(calculator.multiply(2, -2), -4);
}
}
About | Sitemap | Contact