© jason gorman 2003 test-driven analysis & design jason gorman

11
© Jason Gorman 2003 Test-driven Analysis & Design Jason Gorman

Upload: jasper-wade

Post on 24-Dec-2015

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: © Jason Gorman 2003 Test-driven Analysis & Design Jason Gorman

© Jason Gorman 2003

Test-driven Analysis & Design

Jason Gorman

Page 2: © Jason Gorman 2003 Test-driven Analysis & Design Jason Gorman

© Jason Gorman 2003

Test-driven Development

• Write a unit test that the system currently doesn’t pass

• Quickly write the code to pass that test

• Refactor the code to remove any duplication or other design nasties

• Move on to the next unit test

Page 3: © Jason Gorman 2003 Test-driven Analysis & Design Jason Gorman

© Jason Gorman 2003

Test-driven Analysis & Design

• Agree a test scenario at the system level (described purely in terms of inputs and outputs) that the system currently doesn’t pass

• Quickly do the analysis and high-level design for how the system will pass that test

• Implement the design using Test-driven Development

• Customer checks that the test has been passed• Move on to the next system test scenario

Page 4: © Jason Gorman 2003 Test-driven Analysis & Design Jason Gorman

© Jason Gorman 2003

Agreeing System Test Scenarios

[email protected]

********

********

Email Address

Password

Confirm Password

Submit

JasonFirst Name

GormanLast Name

Thank you for registering, Jason Gorman. An email has been sent to [email protected]. To activate your account please click on the activation link in the email.

Registration

Registration ConfirmationClick()

Initial Conditions:

• First Name is not blank• Last Name is not blank• Email Address is valid• Password is not blank• Confirm Password = Password

Action(s): Click Submit button

Outcome:• A new user account is created with a status of Awaiting Activation• The user account’s First Name = Registration First Name• User account’s Last Name = Registration Last Name• User account’s Email = Registration Email• User account’s Password = Registration Password• An email is sent to the User account’s email address, with the subject “<<web site name>> Registration Confirmation”, which contains instructions to activate the user’s account and a link that the user can follow that will set their account’s status to Activated and redirect them to the home page.

Page 5: © Jason Gorman 2003 Test-driven Analysis & Design Jason Gorman

© Jason Gorman 2003

Modeling Initial Conditions

: RegistrationView

firstName = “Jason”lastName = “Gorman”emailAddress = “[email protected]”password = “password”confirmPassword = “password”

: Session

activeView

: Application

: User: User: User

users

sessions

: SmtpServer

webmaster : User

email = “[email protected]

webmaster

users

name = “Somesite”

Page 6: © Jason Gorman 2003 Test-driven Analysis & Design Jason Gorman

© Jason Gorman 2003

Modeling Outcomes

: RegistrationView

firstName = “Jason”lastName = “Gorman”emailAddress = “[email protected]”password = “password”confirmPassword = “password”

: Session

activeView

: Application

: User: User: User

users

sessions

: RegistrationConfirmationViewMessage = “Thank you for registering, Jason Gorman. An email has been sent to [email protected]. To activate your account please click on the activation link in the email.”

activeView

newUser : Userusers

id = 5675firstName = “Jason”lastName = “Gorman”emailAddress = “[email protected]”password = “password”status = #awaitingActivation

: SmtpServer

: Email

to = “[email protected]”from = “[email protected]”subject = “Somesite Registration Confirmation”body = “Please click on the link to activate your account.http://www.somesite.com/activate.aspx?id=5675”

sentItems

name = “Somesite”

webmaster : User

email = “[email protected]

webmaster

users

Page 7: © Jason Gorman 2003 Test-driven Analysis & Design Jason Gorman

© Jason Gorman 2003

Enumerate the outcomes

registration : RegistrationView

firstName = “Jason”lastName = “Gorman”emailAddress = “[email protected]”password = “password”confirmPassword = “password”

session : Session

activeView

application : Application

: User: User: User

users

sessions

confirmation : RegistrationConfirmationViewMessage = “Thank you for registering, Jason Gorman. An email has been sent to [email protected]. To activate your account please click on the activation link in the email.”

activeView

: SmtpServer

: Email

to = “[email protected]”from = “[email protected]”subject = “Somesite Registration Confirmation”body = “Please click on the link to activate your account.http://www.somesite.com/activate.aspx?id=5675”

sentItems

1. confirmation = new RegistrationConfirmationView2. confirmation.message = “Thank you for registering, “ +

registration.firstName + “ “ + registration.lastName” + “. An email has been sent to “ + registration.email + “. To activate your account please click on the activation link in the email.”

3. session.activeView = confirmation4. newUser = new User5. newUser.firstName = registration.firstName6. newUser.lastName = registration.lastName7. newUser.emailAddress = registration.email8. newUser.password = registration.password9. newUser.status = #awaitingActivation10. newUser.id = User.nextId11. application.users = application.users@pre + newUser12. mail = new Email13. mail.to = newUser.emailAddress14. mail.from = application.webmaster.emailAddress15. mail.subject = application.name + “ Registration Confirmation”16. mail.body = “Please click on the link to activate your account.http://www.somesite.com/activate.aspx?id =“ + newUser.id17. mailSewrver.sentItems = mailServer.sentItems + mail

newUser : Userusers

id = 5675firstName = “Jason”lastName = “Gorman”emailAddress = “[email protected]”password = “password”status = #awaitingActivation

webmaster : User

email = “[email protected]

webmaster

users

name = “Somesite”

Page 8: © Jason Gorman 2003 Test-driven Analysis & Design Jason Gorman

© Jason Gorman 2003

Assigning Responsibility For Outcomes

registration : RegistrationView

submit.click()

: RegistrationController

createUser(registration.firstName, registration.lastName, registration.email, registration.password)

newUser : User

User(firstName, lastName, email, password)

application : Application

addUser(newUser)

• newUser.firstName = registration.firstName

• newUser.lastName = registration.lastName

• newUser.emailAddress = registration.email

• newUser.password = registration.password

• newUser.status = #awaitingActivation

• newUser.id = User.nextId

• application.users = application.users@pre + newUser

•newUser = new User

Page 9: © Jason Gorman 2003 Test-driven Analysis & Design Jason Gorman

© Jason Gorman 2003

Interaction models imply a list of unit tests

registration : RegistrationView

submit.click()

: RegistrationController

createUser(registration.firstName, registration.lastName, registration.email, registration.password)

newUser : User

User(firstName, lastName, email, password)

application : Application

addUser(newUser)

[Test]

public void CreateUserTest()

{

string firstName = “Jason”;

string lastname = “Gorman”;

string email = “[email protected]”;

string password = “password’;

int lastId = User.LastId;

User newUser = new User(firstName, lastName, email, password);

Assertion.AssertEquals(firstName, newUser.FirstName);

Assertion.AssertEquals(lastname, newUser.LastName);

Assertion.AssertEquals(email, newUser.EmailAddress);

Assertion.AssertEquals(password, newUser.Password);

Assertion.AssertEquals(newUser.Status = UserStatus.AwaitingActivation;

Assertion.AssertEquals(lastId + 1, newUser.Id);

}

Page 10: © Jason Gorman 2003 Test-driven Analysis & Design Jason Gorman

© Jason Gorman 2003

Next Steps…

• Once you have passed the overall system test (which may require some creative problem solving to handle UI testing) go straight to the customer for acceptance testing• If you get the green light from the customer, move on to the next system test scenario

Page 11: © Jason Gorman 2003 Test-driven Analysis & Design Jason Gorman

© Jason Gorman 2003

Tips

• I often find class diagrams surplus to requirements. The class model is in the code, as far as I’m concerned• If you’re asked to produce a class diagram, consider using the code as the basis for this model (removing any unnecessary implementation detail, of course)• Don’t forget to integrate your changes every few unit tests• Validate that individual user actions, when performed in a sequence, satisfy a use case scenario by acceptance testing of those scenarios. You can also validate them up front to a certain extent by using slideshows that animate the UI from one action to the next. Snapshots put together in a sequence (a “filmstrip”) can also be used to validate in this way – but remember, just because your UI slideshows satisfy the requirements doesn’t mean your code will! You still have to test the real thing. Get that feedback as soon as you can before you consider moving on to the next scenario.