Sending Parameters to test cases.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mike_Oberegger
Posted On:   Tuesday, May 15, 2007 10:57 AM

I apologize if this was posted before. I did a search and everything, and it doesn't seem like the question was posted. I was wondering if there was a way to send parameters to a test. For example, instead of doing this: public class TestMyMath { @Test public final void testAdd() { assertEquals("Bad add.", 12, MyMath.add(6, 6)); } I could do this: public class TestMyMath { @Test public final void testAdd(int a, int b, int exp) { assertEquals("Bad add.", exp, MyMath.add(a, b)); } and I wouldn't have to hardcode any test cases. This way, I could reuse the same test,   More>>

I apologize if this was posted before. I did a search and everything, and it doesn't seem like the question was posted.



I was wondering if there was a way to send parameters to a test. For example, instead of doing this:

			
public class TestMyMath {

@Test
public final void testAdd() {
assertEquals("Bad add.", 12, MyMath.add(6, 6));
}


I could do this:


			
public class TestMyMath {

@Test
public final void testAdd(int a, int b, int exp) {
assertEquals("Bad add.", exp, MyMath.add(a, b));
}


and I wouldn't have to hardcode any test cases. This way, I could reuse the same test, but with different values. Any help would be appreciated.





Thanks.    <<Less

Re: Sending Parameters to test cases.

Posted By:   Robert_Lybarger  
Posted On:   Tuesday, May 15, 2007 06:49 PM

Could you just put the parameter's/argument's values in a properties file instead? Then leave the no-arg methods in place and have them reference the properties file for their values?...
About | Sitemap | Contact