why JTest can not generate negative int for me
My class has a addBalance(int money) method, why test cases generated by JTest always generate positive param for this method, why not generate negative param
calss constructor seen below:
public BankAccountSimple(String customer, int deposit) {
if (!validCustomer(customer)) {
throw new IllegalArgumentException("Bad Customer Name");
}
this.customer = customer;
balance = deposit;
}
method seen below:
public void withdraw(int amount) {
balance = balance - amount;
}
test case seen below:
/**
* Test for method: withdraw(int)
* @see BankAccountSimple#withdraw(int)
* @author Jtest
*/
public void testWithdraw3() {
BankAccountSimple THIS = new BankAccountSimple("0", 0);
// jtest_tested_method
THIS.withdraw(0);
int var0 = THIS.getBalance();
assertEquals(0, var0); // jtest_unverified
boolean var1 = THIS.isVIP();
assertEquals(false, var1); // jtest_unverified
}
/**
* Test for method: withdraw(int)
* @see BankAccountSimple#withdraw(int)
* @author Jtest
*/
public void testWithdraw4() {
BankAccountSimple THIS = new BankAccountSimple("0", 7);
// jtest_tested_method
THIS.withdraw(7);
int var0 = THIS.getBalance();
assertEquals(0, var0); // jtest_unverified
boolean var1 = THIS.isVIP();
assertEquals(false, var1); // jtest_unverified
}
calss constructor seen below:
public BankAccountSimple(String customer, int deposit) {
if (!validCustomer(customer)) {
throw new IllegalArgumentException("Bad Customer Name");
}
this.customer = customer;
balance = deposit;
}
method seen below:
public void withdraw(int amount) {
balance = balance - amount;
}
test case seen below:
/**
* Test for method: withdraw(int)
* @see BankAccountSimple#withdraw(int)
* @author Jtest
*/
public void testWithdraw3() {
BankAccountSimple THIS = new BankAccountSimple("0", 0);
// jtest_tested_method
THIS.withdraw(0);
int var0 = THIS.getBalance();
assertEquals(0, var0); // jtest_unverified
boolean var1 = THIS.isVIP();
assertEquals(false, var1); // jtest_unverified
}
/**
* Test for method: withdraw(int)
* @see BankAccountSimple#withdraw(int)
* @author Jtest
*/
public void testWithdraw4() {
BankAccountSimple THIS = new BankAccountSimple("0", 7);
// jtest_tested_method
THIS.withdraw(7);
int var0 = THIS.getBalance();
assertEquals(0, var0); // jtest_unverified
boolean var1 = THIS.isVIP();
assertEquals(false, var1); // jtest_unverified
}
Tagged:
0
Comments
Notice that these types of tests are not testing the specification of the method, making sure that you get the intended result when subtracting amount from balance. Since Jtest is unable to discern the correct specification just by analyzing the methods, it is up the user to provide the specification tests. Since all of the Jtest test cases are stored in the form of a Junit class, you can easily add your own test cases to the test class or extend one of the automatically generated test cases.
One way to allow Jtest to automatically validate the specification of the code would be to incorporate design by contract into the methods. By adding preconditions and postconditions to the methods, Jtest will automatically create test cases that verify the functionality described in your DbC contracts and will report situations where DbC contracts are violated. More information about Design by Contract can be found in the Jtest Documentation under Jtest User's guide | Concepts | Design by Contract. The language specification can be found in the Jtest Documentation under Jtest User's guide | Reference | The Design by Contract Specification Language.