lundi 9 mars 2015

Correct way to Unit Testing

I've been practicing Unit Testing over the last couple of weeks but I'm not sure I'm testing the correct way.


The system I'm trying to test looks like this on the live system:



  • Quantity

  • Unit Net Sales Price

  • Net Total

  • Sales Tax @ 20%

  • Total


I filled the fields with the following data:



  • Quantity = 6

  • Unit Net Sale Price = 22.00

  • Net Total = 132.00

  • Sales Tax @ 20% = 26.40

  • Total = 158


I created a Unit Test using the assertEquals which passes:



public void testTaxCalculation3() throws Exception{
float quantity = 6;
float netSalePrice = 22.00f;
float taxPercent = 20.00f;

float totalNetPrice = netSalePrice * quantity; //6 multiply 22 = 132.0
float taxAmount = (totalNetPrice * taxPercent) / 100; //132.00 multiply by 20 = 2640 divided by 100 = 26.4
float totalPrice;
totalPrice = totalNetPrice + taxAmount; //132 plus 26.4

Assert.assertEquals((float) 158.40, totalPrice);
}


Is this the right way to write the Unit Test?


Aucun commentaire:

Enregistrer un commentaire