Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2005 Charlie Poole. All rights reserved Test First User Interfaces XP2005 Sheffield University June 18, 2005.

Similar presentations


Presentation on theme: "Copyright © 2005 Charlie Poole. All rights reserved Test First User Interfaces XP2005 Sheffield University June 18, 2005."— Presentation transcript:

1 Copyright © 2005 Charlie Poole. All rights reserved Test First User Interfaces XP2005 Sheffield University June 18, 2005

2 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Schedule 2:00-3:00Introduction Review of Testing Practices Is UI Testing Hard? Message of this Course 3:00Break 3:15-4:15Principles Patterns Practices 4:15Break 4:30-5:30Tools Techniques Conclusion

3 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Introduction

4 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Some Background About Me

5 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Contact Email charlie@pooleconsulting.com cpoole@exoftware.com Web Sites www.charliepoole.org www.pooleconsulting.com Seattle XP Users Group www.seattlexp.org NUnit Testing Framework www.nunit.org

6 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Why Are We Here? What sort of UI work do you do? What platforms do you use? What do you want from this course?

7 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Testing Practices

8 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Agile Development Modern software development methodologies increasingly emphasize agility. – Increased pace of development – Prevalence of unstable requirements Teams need to work as a cohesive unit, with strong communications and continuous feedback. Traditional communication channels often fail in this setting.

9 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Tests in XP Acceptance/Customer Tests – Tied to Requirements – Express customer intention Unit/Programmer Tests – Small units of functionality tested in isolation – Express programmer intention

10 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Tests as Communication For each test there is a message – Criterion for success – Result For each test there are two communicators – Whoever defines the test criteria – Whoever tries to satisfy the test criteria

11 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Tests Communicate Intent From the customer – What the application should do From the developer – How the application will do it

12 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Test-Driven Development A fundamental practice of XP But “extremely” valuable on it’s own Note that the term is overloaded –The practice of writing tests and then making them pass –The “inner cycle” which includes TDD as one element A three-step micro-cycle Make it Fail –No code without a failing test Make it Work –As simply as possible Make it Better –Refactor

13 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved The Circle of Code Simple Design Test-Driven Development Refactoring Continuous Integration

14 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Effect of Continuous Testing The state of the application is known at all times – based on which tests pass. Requirements changes are accepted as a basic condition of development rather than being resisted. Resulting code is more robust and – with continuous integration – can be ready for demos or even delivery at any time.

15 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Automating Tests Tests must be automated if they are to be run as frequently as we need them to run. Tools like SUnit, JUnit, CPPUnit and NUnit provide a framework for automating unit tests. Tools like FIT and Exactor provide a framework for automating acceptance tests.

16 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Is UI Testing Hard?

17 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Exercise What makes UI testing hard for you? Break into groups of three or four… – List things that make UI testing difficult – Identify general versus platform-specific issues – What would be needed to resolve each issue? Select one person to present your answers.

18 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Discussion

19 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved What Makes Testing Hard? Programmer tests aim at test independence But… Testing connected sets of objects is hard – Tests become dependent on one another – Objects have to be put in a known state – It’s hard to figure out what failed

20 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Problems of GUI Testing Tight coupling to other parts of the application – may include business logic UI is implemented as a single large program handling all user interaction Design is driven by IDE code generation Technical issues of the platform

21 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Possible Solutions Tight coupling to other parts of the application – may include business logic – Separate business logic from the UI – Use interfaces to permit substitution – Use factories to create business objects

22 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Possible Solutions UI is implemented as a single large program handling all user interaction – Use separate classes for UI logic – Use separate classes for validation – Use smart controls where feasible

23 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Possible Solutions Design is driven by IDE code generation – Resist the temptation to insert code into an the UI just because the IDE makes it easy. – Explore the limits of your tools – Where possible, split the code into two parts

24 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Possible Solutions Technical issues of the platform – Learn your platform and language thoroughly – Explore key aspects needed for testing UI Event generation and capture Instantiation of UI elements as part of a test Access to contained UI elements – Be clear on what testing is needed

25 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved The “Hardness” Paradox Perhaps “hard to test” is a good thing… – Most of the problems that make GUI testing “hard” are problems of design – “Hardness” can be a signal to look more deeply at how our application is designed – Question: Are ALL such problems signals of design issues? How can we tell?

26 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved The Message

27 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved The Message GUI testing may be hard, but it’s no harder than many other aspects of delivering great software.

28 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved The Message What initially presents as a testing problem usually turns out to be a design problem.

29 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved The Message The design techniques we use to solve GUI testing problems are the same ones we use for business objects.

30 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved The Message GUI testing presents unique technical – as opposed to conceptual – issues.

31 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved The Message The general principles used for GUI testing are platform-independent.

32 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved The Message Some of the lower-level techniques require platform-specific knowledge, even though similar things must be accomplished on every platform.

33 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved The “Hardness” Paradox Perhaps “hard to test” is a good thing… – Most of the problems that make GUI testing “hard” are problems of design – “Hardness” can be a signal to look more deeply at how our application is designed – Question: Are ALL such problems signals of design issues? How can we tell?

34 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved An Objection? Should we be modifying the design merely to make the software easier to test?

35 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Yes, because… Testability is just as valid an objective as security, safety, ease of deployment or any other desirable characteristic Poor testability is almost always due to other problems in the design, particularly poor separation of responsibilities, and excessive coupling between components.

36 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Questions?

37 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Principles

38 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Principles Know exactly what you’re testing – Each test should have one purpose – Do you really need to test it? Too simple to fail Part of the platform

39 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Principles Keep domain logic out of the UI – Use separate domain objects – Test them separately, without the UI – Make the UI as thin as possible – Consider NOT testing it!

40 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Principles Avoid tight coupling with the domain – Use creational patterns that allow substitution – UI should not create domain objects directly – Use interfaces in languages that require them – Mock the domain when testing the UI

41 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Principles Apply separation of concerns to the UI – Separate behavior from display – Use separate classes for validation – Use smart controls judiciously

42 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Principles Avoid code generation pitfalls – Resist the temptation to insert code into an the UI just because the IDE makes it easy. – Explore the limits of your tools – Where possible, split the code into two parts

43 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Principles Learn your platform and language thoroughly – Explore key aspects needed for testing UI Event generation and capture Instantiation of UI elements as part of a test Access to contained UI elements – Be clear on what testing is needed

44 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Principles Understand your own common mistakes – Don’t test getters and setters… unless you habitually mess them up – Don’t test whether event’s are hooked up… unless you often forget to hook them up

45 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Simple GUI Example

46 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Background The NUnit test framework allows users to assign tests to categories and run all the tests in one or more of these categories. A domain object maintains a list of all the available categories and another list of the currently selected categories. The UI must display the available categories and allow users to select those to be used in a run.

47 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved The Model Categories are represented by strings. The available and selected category lists are represented as arrays of strings. Initially, the available category list is hard-coded. The following methods are provided: GetAvailableCategories() GetSelectedCategories() SetSelectedCategories()

48 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Simple GUI

49 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Demonstration

50 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Patterns

51 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Model-View View Model

52 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved MVC View Controller Model

53 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved MVP Presenter View Model With no dynamic features, View can remain ignorant of both Presenter and Model.

54 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved MVP Presenter View Model View delegates event handling to Presenter. This is the classic implementation. Also called HumbleDialog.

55 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Extended GUI Example

56 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Further Tasks Modify SimpleGui to use MVP Add Event Handling to Model Support changing available list asynchronously Make gui richer: add second list box and Add and Remove buttons.

57 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Bits of Advice

58 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Three Rules of UI Testing Get business functions out of the UI – Use domain or controller objects – Test them separately Get UI logic out of the Form – Separate controller objects – Derived or User Controls – Test them separately Know what you’re testing for – Do you really need to test it?

59 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Non-Essentials Things that are usually non-essential – Precise positioning of controls – Shades of color – Exact sizes They become essential – When they are hard requirements – When code depends on them

60 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Specialized Test Frameworks JFCUnit JWebUnit NUnitForms NUnitAsp

61 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Testing Event Handling Test Generation of Events – Use a mock or fake to capture the events Test Handling of Events – Use a fake to send the events

62 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved UI Testing Approaches Testing through the GUI Testing immediately “under the glass” Isolated GUI testing Exploratory testing Visual TDD

63 Test Driven User Interfaces Copyright © 2005 Charlie Poole. All rights reserved Conclusion


Download ppt "Copyright © 2005 Charlie Poole. All rights reserved Test First User Interfaces XP2005 Sheffield University June 18, 2005."

Similar presentations


Ads by Google