So I am extremely new to unit testing! I know how to create some test if in my program there are functions with parameters. How would I test functions without them? Please excuse my lack of knowledge but I have been searching around and have not found any answers!
I am adding code to show how I would test a function with parameters. How would I create a test with a function that takes in no parameters?
Thanks!
func calculateTip(billAmount: Float?, taxPercentage: Float?, tipPercentage: Float?) -> Float? {
let bill = billAmount!
let pTax = taxPercentage!
let pTip = tipPercentage!
let tax = bill * pTax
let total = bill + tax
let tip = total * pTip
return tip
}
Unit test--
func testAllZerosShouldReturnZero() {
let result = calc.calculateTip(0, taxPercentage: 0, tipPercentage: 0)
XCTAssertEqual(result, 0, "should be zero")
}
Aucun commentaire:
Enregistrer un commentaire