0% found this document useful (0 votes)
3 views4 pages

White Box Analysis and JUnit Testing Guide

The document describes the white box and black box analysis of the deposit method of an Account class. Three test paths and expected results for white box testing are identified. The input domain, equivalence classes, and boundary values for black box testing of the withdraw method are also defined. Finally, the code of the Account class is corrected, and the CAccountTest class is added to automate the white box unit tests of the deposit method.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

White Box Analysis and JUnit Testing Guide

The document describes the white box and black box analysis of the deposit method of an Account class. Three test paths and expected results for white box testing are identified. The input domain, equivalence classes, and boundary values for black box testing of the withdraw method are also defined. Finally, the code of the Account class is corrected, and the CAccountTest class is added to automate the white box unit tests of the deposit method.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Conduct a comprehensive white box analysis of the input method.

oGrafo:

Cyclomatic complexity:

Calculation method Complexity


Number of regions 3
Number of edges - number of nodes + 2 8 -7 + 2= 3
Number of conditions + 1 2+1=3

Test paths:
Limit values:

Atributo: cantidad
Domain Class Type Lower limit Upper limit
Decimal numbers with (-∞, 0] Invalid -∞ 0
floating point (double)
(0,≤dBalance ] Valid 0 <=dBalance
(> dSaldo, +∞) Not valid Balance +∞

Test design:

Method: withdraw
No test amount to withdraw Expected output
1 -100 ERROR
2 -1 ERROR
3 0 balance = balance - 0
4 100 && <=dBalance balance = balance - 100
5 1000 && > dBalance ERROR

Create the CCuentaTest class of the JUnit Test Case type in Eclipse that allows us to pass the white box unit tests of the ingresar method. The
You must have obtained the test cases in the first section of the exercise.

Corrected Account Code:


public class CAccount {

public static void main(String[] args) {


Debugging. It always stops.
CCuenta myAccount = new CCuenta();

[Link]("Saldo Incial: " + [Link] + " euros");


Debugging. Causes a stop due to input with an amount less than 0
[Link](-100);
Initial Balance:
[Link](0);
Balance after deposit:
[Link](200);
Balance after deposit:
Debugging. Causes stop with third income condition
[Link](300);
Balance after deposit:
[Link](50);
Balance after withdrawal:
}

// Properties of the Account Class


public double dSaldo;
/*autor = ANTONIO MARTIN.
We create the variable numeroIngreso of which each object will have its copy.
We create the class field numeroIngresoSig with a counter that will be shared by all objects.
*/
public int entryNumber;
private static int nextInputNumber = 1;
iCodErr = 2;

}
else
{
Debugging. Breakpoint. Only on entry 3
{
dSaldo = dSaldo + amount;
iCodErr = 0;
}
}
else {//author = ANTONIO MARTIN. Error shown if attempts are made to make more deposits
ERROR! No more than 3 entries can be made.
}

// Debugging. Breakpoint when the amount is less than 0


return iCodErr;
}

Method to withdraw amounts from the account. Modifies the balance.


This method will be tested with Junit
*/
public void retirar (double cantidad)
{
if (amount <= 0)
{
Cannot withdraw a negative amount
}
else if (dSaldo < amount)
{
Not enough balance

}
else
{
dSaldo = dSaldo - amount;
}

}
}
The corrected CcuentaTest code:

import static [Link].*;

import [Link];
import [Link];
import [Link];

class CCuentaTest {
CCuenta myAccount = new CCuenta();

@ParameterizedTest
@CsvSource({"-10,1","0,2","10,0"})
Generate the following breakpoints to validate the behavior of the enter method in debug mode.
Breakpoint without condition when creating the miCuenta object in the main function. Line 3 of the main method code presented in the following.
page of this book.

Breakpoint at the return instruction of the ingresar method only if the amount to enter is less than 0. Line 20 of the ingresar method code.
which is presented later.

Breakpoint in the instruction where the balance is updated, it should only stop the third time it is updated. Line 16 of the code.
of the method to be introduced later.

You might also like