Following is my code for interfaces, and three classes. I use JUNIT testing and the JUnit test class is also below. However I have no idea to pass the parameters from my concrete classes and use it in JUnit class.
Interface
ArithmeticSkeleton.java
public interface ArithmeticSkeleton {
int operation(int a, int b);
}
Concrete Class For Division
Divide.java
public class Divide implements ArithmeticSkeleton{
@Override
public int operation(int a, int b) {
return (a / b);
}
}
Concrete Class For Multiplication
Multiply.java
public class Multiply implements ArithmeticSkeleton{
@Override
public int operation(int a, int b) {
return (a * b);
}
}
Concrete Class For Addition
Addition.java
public class Addition implements ArithmeticSkeleton{
@Override
public int operation(int a, int b) {
return (a + b);
}
}
JUnit Test Class
ArithmeticSkeletonTest.java
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class ArithmeticSkeletonTest {
public ArithmeticSkeleton asInterface;
public Divide div;
public ArithmeticSkeletonTest(ArithmeticSkeleton asInterface) {
this.asInterface = asInterface;
}
@Parameterized.Parameters
public static Collection<Object[]> testInstances(){
return Arrays.asList(
new Object[]{new Multiply()},
new Object[]{new Addition()},
new Object[]{new Subtraction()},
new Object[]{new Divide()}
);
}
}
how to test it on ArithmeticSkeletonTest.java
Aucun commentaire:
Enregistrer un commentaire