I have developed a web base application that in some way let's the user submit a test case just by inputting values instead of writing a complete JUnit test.
The way I used till now is generating a test class for each submission and then compile it and run.
For example assume we have a class like bellow:
public class CalculatorO
{
public boolean isPrime( int n )
{
if (n < 2) {
return false;
}
int count = 0;
for (int i = 1; i <= n; i++) {
if (n % i == 0) {
count++;
}
}
if (count == 2) {
return true;
} else {
return false;
}
}
}
As oracle, and another class like bellow:
public class CalculatorM0
{
public boolean isPrime( int n )
{
if (n < 2) {
return false;
}
int count = 0;
for (int i = 1; i <= n; i++) {
if (n * i == 0) {
count++;
}
}
if (count == 2) {
return true;
} else {
return false;
}
}
}
As subject of the test. Then I generate a test template as following:
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals;
import org.junit.Test;
public class {{TestClassName}} {
@Test
public void {{MethodName}}() {
int AO = {{valueA}};
int AM = {{valueA}};
{{OriginalClassName}} {{OriginalClassNameLower}} = new {{OriginalClassName}}();
{{MutantClassName}} {{MutantClassNameLower}} = new {{MutantClassName}}();
{{MethodReturnType}} resultO = {{OriginalClassNameLower}}.{{MethodName}}(AO);
{{MethodReturnType}} resultM = {{MutantClassNameLower}}.{{MethodName}}(AM);
assertEquals(resultO, resultM);
}
}
Then for example when a user submits a number 3 as input value, I manipulate the test template like this:
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals;
import org.junit.Test;
public class CalculatorOCalculatorM0Test30099 {
@Test
public void isPrime() {
int AO = 3;
int AM = 3;
CalculatorO calculatorO = new CalculatorO();
CalculatorM3 calculatorM3 = new CalculatorM3();
boolean resultO = calculatorO.isPrime(AO);
boolean resultM = calculatorM3.isPrime(AM);
assertEquals(resultO, resultM);
}
}
Then I compile the test case and run it.
The main issue is that this cycle occurs often and because of the load forced to the server, because of files being created and compiled, the server faces low memory issue and crashes much.
I am looking for a way to create the test case one time and build it one time then run it for each input with arguments.
I mean something like this:
java -cp .;../../JUnitLibs/junit-4.12.jar;../../JUnitLibs/hamcrest-core-1.3.jar org.junit.runner.JUnitCore CalculatorOCalculatorM0Test30099 > CalculatorOCalculatorM0Test30099Result -input 3