1 / 11

Test-driven Analysis & Design

Test-driven Analysis & Design. Jason Gorman. 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.

matty
Télécharger la présentation

Test-driven Analysis & Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Test-driven Analysis & Design Jason Gorman © Jason Gorman 2003

  2. 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 © Jason Gorman 2003

  3. 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 © Jason Gorman 2003

  4. 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. Agreeing System Test Scenarios Registration Jason First Name Gorman Last Name jason@objectmonkey.com Email Address Password ******** Confirm Password ******** Submit Click() Registration Confirmation Thank you for registering, Jason Gorman. An email has been sent to jason@objectmonkey.com. To activate your account please click on the activation link in the email. © Jason Gorman 2003

  5. Modeling Initial Conditions : Application : Session webmaster webmaster : User activeView : RegistrationView email = “webmaster@somesite.com” firstName = “Jason” lastName = “Gorman” emailAddress = “jason@objectmonkey.com” password = “password” confirmPassword = “password” users sessions : SmtpServer : User : User : User users name = “Somesite” © Jason Gorman 2003

  6. Modeling Outcomes : Application : Session webmaster webmaster : User activeView : RegistrationView email = “webmaster@somesite.com” firstName = “Jason” lastName = “Gorman” emailAddress = “jason@objectmonkey.com” password = “password” confirmPassword = “password” users sessions : RegistrationConfirmationView Message = “Thank you for registering, Jason Gorman. An email has been sent to jason@objectmonkey.com. To activate your account please click on the activation link in the email.” : SmtpServer sentItems activeView : Email to = “jason@objectmonkey.com” from = “webmaster@somesite.com” subject = “Somesite Registration Confirmation” body = “Please click on the link to activate your account. http://www.somesite.com/activate.aspx?id=5675” newUser : User : User : User users : User id = 5675 firstName = “Jason” lastName = “Gorman” emailAddress = “jason@objectmonkey.com” password = “password” status = #awaitingActivation users name = “Somesite” © Jason Gorman 2003

  7. confirmation = new RegistrationConfirmationView • 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.” • session.activeView = confirmation • newUser = new User • 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 • mail = new Email • mail.to = newUser.emailAddress • mail.from = application.webmaster.emailAddress • mail.subject = application.name + “ Registration Confirmation” • mail.body = “Please click on the link to activate your account. • http://www.somesite.com/activate.aspx?id =“ + newUser.id • mailSewrver.sentItems = mailServer.sentItems + mail Enumerate the outcomes application : Application session : Session webmaster webmaster : User activeView registration : RegistrationView email = “webmaster@somesite.com” firstName = “Jason” lastName = “Gorman” emailAddress = “jason@objectmonkey.com” password = “password” confirmPassword = “password” users sessions confirmation : RegistrationConfirmationView Message = “Thank you for registering, Jason Gorman. An email has been sent to jason@objectmonkey.com. To activate your account please click on the activation link in the email.” : SmtpServer sentItems activeView : Email to = “jason@objectmonkey.com” from = “webmaster@somesite.com” subject = “Somesite Registration Confirmation” body = “Please click on the link to activate your account. http://www.somesite.com/activate.aspx?id=5675” newUser : User : User : User users : User id = 5675 firstName = “Jason” lastName = “Gorman” emailAddress = “jason@objectmonkey.com” password = “password” status = #awaitingActivation users name = “Somesite” © Jason Gorman 2003

  8. Assigning Responsibility For Outcomes registration : RegistrationView : RegistrationController application : Application submit.click() createUser(registration.firstName, registration.lastName, registration.email, registration.password) User(firstName, lastName, email, password) newUser : User • newUser = new User 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 © Jason Gorman 2003

  9. Interaction models imply a list of unit tests registration : RegistrationView : RegistrationController application : Application submit.click() createUser(registration.firstName, registration.lastName, registration.email, registration.password) User(firstName, lastName, email, password) newUser : User • [Test] • public void CreateUserTest() • { • string firstName = “Jason”; • string lastname = “Gorman”; • string email = “jason@objectmonkey.com”; • 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); • } addUser(newUser) © Jason Gorman 2003

  10. 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 © Jason Gorman 2003

  11. 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. © Jason Gorman 2003

More Related