unit testing

10

Click here to load reader

Upload: brian-hu

Post on 29-Jun-2015

67 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Unit testing

Unit TestingBrian Hu

Page 2: Unit testing

Why Test

• Catch errors

• Help you write code

• Speed up your development

• Cover configurations

• Cover new co-workers

Page 3: Unit testing

What is a unit test

• Tests ONE thing

• Single “unit” of functionality

• Small, fast, ISOLATED

Page 4: Unit testing

Unit Tests don’t cover

• Performance

• UI interaction

• Whole system integration

Page 5: Unit testing

Guidelines• Testing should be automated and non-interactive

• Let your code JUST pass the test

• Remember to test boundary cases, but also remember that it’s impossible to test every case

• Provide a random generator when it’s possible

• Keep testing at unit level

• Act as 3rd party class consumer

• Passed tests don’t promise the correctness of code

Page 6: Unit testing

XCTest

Page 7: Unit testing

Tutorial Project http://is.gd/nDMTWU

Page 8: Unit testing

Instruction• We have 4 tests in this project: testValidateEmail,

testSubmit, testIsEmpty, testValidatePassword

• I’ll do the “testValidateEmail” step by step for you.

• I have written the tests of “testIsEmpty” and “testSubmit” for you. Please implement the logic by yourself.

• Please write the test and implement the logic for the last test by yourself.

Page 9: Unit testing

API you may need

#if DEBUG [NSException raise:@“Invalid Email Exception” format:@"email is invalid”]; #endif

Page 10: Unit testing

Password requirement

• length between 6~12

• has at least 1 uppercase letter and 1 lowercase letter