Can AssertEquals be applied for different data typed input and outputs ?When I have applied AssertEquals to different data typed input and output,the AssertEquals gets striked off..and even the successful test case are not passing ?
What I meant by different data typed input and outputs means..Say example,Consider a program to check whether a number is even or odd.The input to this program is a number which is 'int' data type and output to this program is a 'String' datatype,which prints the number is "even" or "odd".
Here is the code
package BasicTesting;
import java.util.*;
class EvenOdd
{
public static void main(String args[])
{
System.out.println("Enter any integer to check whether its odd or even...");
Scanner ob = new Scanner(System.in);
int i;
i = ob.nextInt();
OddEven(i);
}
public static void OddEven(int i) {
if(i%2==0)
{
System.out.println("You entered an even number");
}
else
{
System.out.println("You entered an odd number");
}
}
}
This is the JUnit test case I have tried to written...but there are some errors in it because of the different data types. package BasicTesting;
import static org.junit.Assert.*;
import org.junit.Test;
public class EvenOddTest {
@Test
public static void test() {
// TODO Auto-generated method stub
EvenOdd a=new EvenOdd();
//int res=a.OddEven(10);
assertEquals("You entered an even number",a.OddEven(10));
}
}
Please help me to write parameterized JUnit test case.Hope you will help.
If you're trying to compare different data types, like int with long something like this -
You can wrap the values in BigDecimal and compare like this -
Note - Usage of BigDecimal will also add some overhead.