CSCE 747 Software Testing and Quality Assurance

CSCE 747 Software Testing and Quality Assurance

CSCE 747 Software Testing and Quality Assurance Lecture 14 Test Driven Object Oriented Design Example 10/16/2013 Lec 14 TDOOD-Example 1 1 CSCE 747 Fall 2013 02/06/2020 Last Time

Growing Object Oriented Software Agile Manifesto Iterative Projects Progress Tests vs Unit Tests Start Testing with the Simplest Success Case Unit-Test Behavior, Not Methods Listen to the Tests How Writing a Test First Helps the Design The Tests Say Only Mock Types That You Own Lec 14 TDOOD-Example 2

Today Growing Object Oriented Software Example: Snipper Jorgensen, Paul C. Software Testing A Craftsman Approach CSCE 747 Fall 2013 2 Write an Adapter Layer If we dont want to mock an external API,

how can we test the code that drives it? We will have used TDD to design interfaces for the services our objects need which will be defined in terms of our objects Lec 14 TDOOD-Example 3 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Mock Application Objects in Integration Tests As described above, adapter objects are passive, reacting to

calls from our code. Sometimes, adapter objects must call back to objects from the application. Event-based libraries, for example, usually expect the client to provide a callback object to be notified when an event happens. In this case, the application code will give the adapter its own event callback (defined in terms of the application domain). The adapter will then pass an adapter callback to the external library to receive external events and translate them for the application callback. Lec 14 TDOOD-Example 4 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce

CSCE 747 Fall 2013 Lec 14 TDOOD-Example 5 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Commissioning an Auction Sniper we are commissioned to build an application that automatically bids in auctions. We sketch out how it should work and what the major components should be. We put together a rough plan for the

incremental steps in which we will grow the application. Lec 14 TDOOD-Example 6 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Requirements: Terminology Requirements discussions with customer and agree on some basic terms: Item is something that can be identified and bought. Bidder is a person or organization that is interested in

buying an item price for an item. Current price is the current highest bid for the item. Stop price is the most a bidder is prepared to pay for an item. Auction is a process for managing bids for an item. Auction house is an institution that hosts auctions. Lec 14 TDOOD-Example 7 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Snipper: Java Swing application run on a desktop and allow the user to bid for

multiple items at a time. It will show the identifier, stop price, and the current auction price and status for each item its sniping. Buyers will be able to add new items for sniping through the user interface, and the display values will change in response to events arriving from the auction house Lec 14 TDOOD-Example 8 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013

First Draft of User Interface Lec 14 TDOOD-Example 9 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 XMPP: the eXtensible Messaging and Presence Protocol Lec 14 TDOOD-Example 10 Growing Object-Oriented Software, Guided by Tests

Freeman and Pryce CSCE 747 Fall 2013 Communicating with an Auction The Auction Protocol - The protocol for messages between a bidder and an auction house is simple. Bidders send commands, which can be: Join - A bidder joins an auction. The sender of the XMPP message identifies the bidder, and the name of the chat session identifies the item. Bid - A bidder sends a bidding price to the auction. Price - An auction reports the currently accepted price. Close - An auction announces that it has closed. The winner of the last price event has won the auction.

Lec 14 TDOOD-Example 11 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Bidder state machine Lec 14 TDOOD-Example 12 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013

Getting it Started We can cut through this first-feature paradox by splitting it into two smaller problems. First, work out how to build, deploy, and test a walking skeleton, then use that infrastructure to write the acceptance tests for the first meaningful feature. Lec 14 TDOOD-Example 13 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce

CSCE 747 Fall 2013 The Walking Skeleton A walking skeleton is an implementation of the thinnest possible slice of real functionality that we can automatically build, deploy, and test end-to-end Lec 14 TDOOD-Example 14 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013

Deciding the Shape of the Walking Skeleton context of the first test Lec 14 TDOOD-Example 15 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Prioritize Initial Requirements 1. Single item: join, lose without bidding This is our starting case where we put together the core infrastructure. 2. Single item: join, bid, and lose

Add bidding to the basic connectivity. 3. Single item: join, bid, and win - Distinguish who sent the winning bid. 4. Show price details - Start to fill out the user interface. 5. Multiple items - Support bidding for multiple items in the same application. 6. Add items through the user interface Implement input via the user interface. 7. Stop bidding at the stop price - More intelligence in the Sniper algorithm. Lec 14 TDOOD-Example 16 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce

CSCE 747 Fall 2013 Iteration Zero In most Agile projects, theres a first stage where the team is doing initial analysis, setting up its physical and technical environments, and otherwise getting started. The team isnt adding much visible functionality since almost all the work is infrastructure call this step iteration zero: iteration because the team still needs to time-box its activities and zero because its before functional development starts in iteration one. One important task for iteration zero is to use the walking

skeleton to test-drive the initial architecture. Lec 14 TDOOD-Example 17 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Our First Test The thinnest slice we can imagine testing is that the Auction Sniper can join an auction and then wait for it to close start by writing a test as if its implementation

already exists, and then filling in whatever is needed to make it work what Abelson and Sussman call programming by wishful thinking Lec 14 TDOOD-Example 18 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 What First; then How focus on what we want the system to do instead of getting caught up in the complexity of how we will make it work

Lec 14 TDOOD-Example 19 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 A First Test: join, lose 1. When an auction is selling an item, 2. And an Auction Sniper has started to bid in that auction, 3. Then the auction will receive a Join request from the Auction Sniper. 4. When an auction announces that it is Closed,

5. Then the Auction Sniper will show that it lost Lec 14 TDOOD-Example 20 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Requirements Feedback Lec 14 TDOOD-Example 21 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce

CSCE 747 Fall 2013 State Machine Lec 14 TDOOD-Example 22 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Stub for Online Auction Southabees On-Line test services are not freely available.

book ahead and pay for each test session Well need a fake auction service, a stub simple as we can make it. connect to an XMPP message broker receive commands from the Sniper and allow the test to send back events. Lec 14 TDOOD-Example 23

Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Test 1 Lec 14 TDOOD-Example 24 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013

Auction Stub We need to find or write four components: 1. an XMPP message broker, 2. a stub auction that can communicate over XMPP, 3. a GUI testing framework, and 4. a test harness that can cope with our multithreaded, asynchronous architecture. Lec 14 TDOOD-Example 25 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013

End-to-End Test Rig Lec 14 TDOOD-Example 26 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Window Licker A framework for the test-driven development of Java systems through the GUI. Features Provides a high-level API for controlling and making assertions about

graphical user interfaces: Swing Dynamic HTML (aka "AJAX") including GWT Deals with the asynchronous nature of GUI and AJAX programming so the tests don't have to Controls the GUI by sending native mouse and keyboard events Handles different keyboard layouts Produces high quality error messages to help you easily diagnose test failures Easily extensible to cope with new user interface components Lec 14 TDOOD-Example 27 https://code.google.com/p/windowlicker/

CSCE 747 Fall 2013 Application Runner Lec 14 TDOOD-Example 28 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Lec 14 TDOOD-Example 29 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce

CSCE 747 Fall 2013 Lec 14 TDOOD-Example 30 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Fake Auction Server Lec 14 TDOOD-Example 31

Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 A Minimal Fake Implementation Lec 14 TDOOD-Example 32 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013

Lec 14 TDOOD-Example 33 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 Lec 14 TDOOD-Example 34 Growing Object-Oriented Software, Guided by Tests Freeman and Pryce CSCE 747 Fall 2013 X-windows

Client-server graphics server runs remote clients events mouse click, movement keyboard press callbacks Lec 14 TDOOD-Example 35

http://en.wikipedia.org/wiki/ X_Window_System_protocols_and_architecture CSCE 747 Fall 2013 X-windows Design principles Bob Scheifler and Jim Gettys set out the early principles of X Do not add new functionality unless an implementor cannot complete a real application without it. It is as important to decide what a system is not as to decide what it is. Do not serve all the world's needs; rather, make the system extensible so that additional needs can be met in an upwardly compatible fashion. The only thing worse than generalizing from one example is generalizing from no examples at all.

If a problem is not completely understood, it is probably best to provide no solution at all. If you can get 90 percent of the desired effect for 10 percent of the work, use the simpler solution. (See also Worse is better.) Isolate complexity as much as possible. Provide mechanism rather than policy. In particular, place user interface policy in the clients' hands. Lec 14 TDOOD-Example 36 http://en.wikipedia.org/wiki/ X_Window_System_protocols_and_architecture CSCE 747 Fall 2013 X-windows

the client and the server exchange four types of packets : Request: the client requests information from the server or requests it to perform an action. Reply: the server responds to a request. Not all requests generate replies. Event: the server sends an event to the client, e.g., keyboard or mouse input, or a window being moved, resized or exposed. Error: the server sends an error packet if a request is invalid. Since requests are queued, error packets generated by a request may not be sent immediately. The X server provides a set of basic services. The client programs realize more complex functionalities by interacting with the server. Lec 14 TDOOD-Example 37

http://en.wikipedia.org/wiki/ X_Window_System_protocols_and_architecture CSCE 747 Fall 2013 X-windows

Windows Identifiers Attributes and properties Events Color modes Xlib and other client libraries Selections, cut buffers, and drag-and-drop Window manager Lec 14 TDOOD-Example 38 http://en.wikipedia.org/wiki/ X_Window_System_protocols_and_architecture

CSCE 747 Fall 2013 Java-Swing What is the best testing tool for Swing-based applications? [closed] Lec 14 TDOOD-Example 39 http://en.wikipedia.org/wiki/ X_Window_System_protocols_and_architecture CSCE 747 Fall 2013 Testing Swing Applications

Lec 14 TDOOD-Example 40 http://www.coderanch.com/t/95772/Testing/ Testing-Swing-Applications CSCE 747 Fall 2013 Lec 14 TDOOD-Example 41 CSCE 747 Fall 2013 Lec 14 TDOOD-Example 42 CSCE 747 Fall 2013

Unit Testing Guis An important part of UnitTestingGuis is not to have to. Seriously, GUIs should be as thin and contain as little logic as possible. If the GUI additionally is only loosely coupled to the business logic (via ModelViewController ? or ModelViewPresenter?), UnitTestingGuis should become rather simple. A good example on testing Swing UIs with pure JUnit can be found at http://www.xp123.com/xplor/xp0001/index.shtml If you still need to write more complicated tests, take a look at http://jfcunit.sourceforge.net/ Lec 14 TDOOD-Example 43 http://www.coderanch.com/how-to/java/ CSCE 747 Fall 2013

UnitTestingGuis http://xp123.com/articles/the-testcodecycle-in-xp-part-2-gui/ developing a simple search engine develop and test the model first Lec 14 TDOOD-Example 44 CSCE 747 Fall 2013 public class SearcherFactory { public static Searcher get(String s) throws

IOException {...} } public interface Searcher { public Result find(Query q); } public class Query { public Query(String s) {...} public String getValue() {...} } Lec 14 TDOOD-Example 45 CSCE 747 Fall 2013 public interface Result { public int getCount();

public Document getItem(int i); } public interface Document { public String getAuthor(); public String getTitle(); public String getYear(); } Lec 14 TDOOD-Example 46 CSCE 747 Fall 2013 The GUI Connection What we'd like to happen: a searcher is associated with the GUI a query is entered

the button is clicked the table fills up with the result Lec 14 TDOOD-Example 47 CSCE 747 Fall 2013 Testing Key Widgets We proposed a screen design earlier. The first thing we can test is that key widgets are present: a label, a query field, a button, and a table. There may be other components on the panel (e.g., sub-panels used for organization), but we don't care about them. So, we'll create testWidgetsPresent(). To make this work, we need a panel for the overall screen ("SearchPanel"),

the label ("searchLabel"), a textfield for entering the query ("queryField"), a button ("findButton"), and a table for the results ("resultTable"). We'll let these widgets be package-access, so our test can see them. Lec 14 TDOOD-Example 48 CSCE 747 Fall 2013 public void testWidgetsPresent() { SearchPanel panel = new SearchPanel(); assertNotNull(panel.searchLabel); assertNotNull(panel.queryField); assertNotNull(panel.findButton); assertNotNull(panel.resultTable); }

Lec 14 TDOOD-Example 49 CSCE 747 Fall 2013 Things to notice: The test helped design the panel's (software) interface. The test is robust against even dramatic rearrangements of the widgets. We took very small steps, bouncing between test, code, and design. Our panel might not (and in fact, does not) actually display anything we haven't tested that. The panel still doesn't do anything (e.g., if the button were clicked).

Lec 14 TDOOD-Example 50 CSCE 747 Fall 2013 public void testInitialContents() { SearchPanel sp = new SearchPanel(); assertEquals("Search:", sp.searchLabel.getText()); assertEquals("", sp.queryField.getText()); assertEquals("Find", sp.findButton.getText()); assert("Table starts empty", sp.resultTable.getRowCount() == 0); } Lec 14 TDOOD-Example 51

CSCE 747 Fall 2013 Testing Interconnection public void testSearcherSetup() { Searcher s = new Searcher() { public Result search(Query q) { return null; } }; SearchPanel panel = new SearchPanel(); assert ("Searcher not set", panel.getSearcher() != s); panel.setSearcher(s); assert("Searcher now set", panel.getSearcher() == s); }

Lec 14 TDOOD-Example 52 CSCE 747 Fall 2013 Testing with a Fake Searcher public void testTestSearcher() { assertEquals(new Query("1").getValue(), "1"); Document d = new TestDocument(1); assertEquals("y1", d.getYear()); Result tr = new TestResult(2); assert(tr.getCount() == 2); assertEquals("a0", tr.getItem(0).getAuthor()); TestSearcher ts = new TestSearcher(); tr = ts.find(ts.makeQuery("2")); assert("Result has 2 items", tr.getCount() == 2);

assertEquals("y1", tr.getItem(1).getYear()); } Lec 14 TDOOD-Example 53 http://xp123.com/articles/the-testcodecycle-in-xp-part-2-gui/ CSCE 747 Fall 2013 public class TestDocument implements Document { int count; public TestDocument(int n) {count = n;} public String getAuthor() {return "a" + count;} public String getTitle() {return "t" + count;} public String getYear() {return "y" + count;} }

Lec 14 TDOOD-Example 54 http://xp123.com/articles/the-testcodecycle-in-xp-part-2-gui/ CSCE 747 Fall 2013 Adapter Stub public class ResultTableAdapter extends DefaultTableModel { public ResultTableAdapter(Result r) {} } Lec 14 TDOOD-Example 55

http://xp123.com/articles/the-testcodecycle-in-xp-part-2-gui/ CSCE 747 Fall 2013 Adapter Implementation Test First public void testResultTableAdapter() { Result result = new TestResult(2); ResultTableAdapter rta = new ResultTableAdapter(result); assertEquals("Author", rta.getColumnName(0)); assertEquals("Title", rta.getColumnName(1)); assertEquals("Year", rta.getColumnName(2)); assert("3 columns", rta.getColumnCount() == 3); assert("Row count=2", rta.getRowCount() == 2); assertEquals("a0", rta.getValueAt(0,0).toString()); assertEquals("y1", rta.getValueAt(1,2).toString());

} Lec 14 TDOOD-Example 56 http://xp123.com/articles/the-testcodecycle-in-xp-part-2-gui/ CSCE 747 Fall 2013 public class ResultTableAdapter extends AbstractTableModel implements TableModel { final static String columnNames[] = {"Author", "Title", "Year"}; Result myResult; public ResultTableAdapter(Result r) {myResult = r;} public String getColumnName(int i) {return columnNames[i];} public int getColumnCount() {return columnNames.length;}

public int getRowCount() {return myResult.getItemCount();} public Object getValueAt(int r, int c) { Document doc = myResult.getItem(r); switch(c) { case 0: return doc.getAuthor(); case 1: return doc.getTitle(); case 2: return doc.getYear(); default: return "?"; http://xp123.com/articles/the-testcodeLec }14 TDOOD-Example 57 cycle-in-xp-part-2-gui/ CSCE 747 Fall 2013 Testing for Looks We have a properly connected panel. We can

check the widgets' relative locations: label left-of queryField queryField left-of findButton queryField above table Lec 14 TDOOD-Example 58 http://xp123.com/articles/the-testcodecycle-in-xp-part-2-gui/ CSCE 747 Fall 2013 Testing for Looks public void testRelativePosition() { SearchPanel sp = new SearchPanel(); JFrame display = new JFrame("test");

display.getContentPane().add(sp); display.setSize(500,500); display.setVisible(true); //try {Thread.sleep(3000);} catch (Exception ex) {} assert ("label left-of query", sp.searchLabel.getLocationOnScreen().x < sp.queryField.getLocationOnScreen().x); Lec 14 TDOOD-Example 59 http://xp123.com/articles/the-testcodecycle-in-xp-part-2-gui/ CSCE 747 Fall 2013

Recently Viewed Presentations

  • FileNewTemplate

    FileNewTemplate

    FY17 OCAS Review. Does the Superintendent's total compensation for Job Class 115 match what has been reported on the district's School Personnel Report -Superintendent SPR Comparison Report. Object Code to Object Code for expenditures recorded under job class 115. OCAS...
  • What is the message of the cartoon? C

    What is the message of the cartoon? C

    To understand what a hurricane or tropical storm is. To be able to explain how a hurricane forms. Outcomes. A completed description and explanation of Tropical Storm Location. A drawn cross section of a tropical storm. A flow chart explaining...
  • Protist Behavioral Responses to Micromolar Levels of ...

    Protist Behavioral Responses to Micromolar Levels of ...

    Wood (1985) showed that tubocurarine binds to mechanoreceptors responsible for contraction in Stentor, which are located on the cell surface (Wood, 1989). Here, we characterize cell-surface binding of the tritiated amino acids proline and serine, and show binding is consistent...
  • 1 Curriculum Night 2019-2020 Fifth Grade 2 The

    1 Curriculum Night 2019-2020 Fifth Grade 2 The

    The mission of Treasure Coast Classical Academy is to train the minds and improve the hearts of young people through a content-rich classical education in the liberal arts and sciences, with instruction in the principles of moral character and civic...
  • Intellectual Freedom in Missouri: Past, Present, and Future

    Intellectual Freedom in Missouri: Past, Present, and Future

    Dr. Charles Davis - FOI specialist Intellectual Freedom in Missouri: Past, Present, and Future Speaker, Paula Martin, Instructional and Reference Librarian Interested in Intellectual Freedom? Not sure where to get started? Want to know . more about what Missouri librarians...
  • Courtly Love - Worth County Schools

    Courtly Love - Worth County Schools

    Courtly Love Poems and Songs. The ideals of courtly love was publicized in the poems, ballads, writings and literary works of various authors of the Middle Ages.Geoffrey Chaucer, the most famous author of the Middle Ages, wrote stories about courtly...
  • Starting and Maintaining Youth Advisory Boards

    Starting and Maintaining Youth Advisory Boards

    Dawn - welcome. Thank you for joining us today! This is the third of a three part webinar series on Starting and Maintaining Youth Advisory Boards. This series is produced by KASA, Kids as Self Advocates in partnership with The...
  • Overwhelmed by Wellness? Time to put the Health

    Overwhelmed by Wellness? Time to put the Health

    Orru, Übner and Orru (2011) discuss the use of muds, peat and peloids in healing, for example, several European countries such as Germany, Austria, Czech Republic, Hungary where there has been some research on the benefits.