Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit Testing CLUE PLAYERS.  How much design do we do before we begin to code?  Waterfall: Design it all! (slight exaggeration… but not much)  Agile:

Similar presentations


Presentation on theme: "Unit Testing CLUE PLAYERS.  How much design do we do before we begin to code?  Waterfall: Design it all! (slight exaggeration… but not much)  Agile:"— Presentation transcript:

1 Unit Testing CLUE PLAYERS

2  How much design do we do before we begin to code?  Waterfall: Design it all! (slight exaggeration… but not much)  Agile: Just enough  Why? We aren’t good at planning entire systems at once.  Is it possible to test without knowing the entire program structure?  Yes! But it can feel uncomfortable at first.  Benefit: it can make us produce code that is more modular, because we need to define/test individual pieces. TDD IS HARD! BUT GOOD…

3 Specification.  Computer needs to make a suggestion which includes a room, a weapon, and a person.  Do we need to know all the details of how the game operates? No, if we can define what this method must do, we can focus on that.  Room must match the location of the player. This method is ONLY concerned with making a suggestion… so we don’t care how the method is called. All we need to know is that the method will take a BoardCell location as a parameter, to enable us to get the room. EXAMPLE: MAKE SUGGESTION Advantage: May lead to more modular code – which is more testable and maintainable!

4  Weapon must be selected. Should be randomly chosen from all weapons that are not in my hand (myCards) and have not previously been seen (seenCards).  Do we care how cards were dealt? No, this method assumes myCards is already set up.  Do we care when/how we “see” cards? No, this method assumes seenCards is already set up.  Similar considerations for Person MAKE SUGGESTION, CONT.

5  Should we return the “suggestion” or store it?  It seems likely that we’ll want to return it, so that it can be “handled” – i.e., disproved  But it’s a quick/easy change between returning vs storing in an instance variable and providing a getter. So either option is valid for now. MAKE SUGGESTION, CONT.

6  What if we decide later to pass the room as a String, rather than a BoardCell?  Takes about 2 minutes to update the test from something like:  makeSuggestion(board.getCellAt(5,7); to  makeSuggestion(“Kitchen”);  Then update the code  remove “lookup” of room  replace with parameter  Run the tests ONCE THEY PASS, TESTS SHOULD ALWAYS PASS


Download ppt "Unit Testing CLUE PLAYERS.  How much design do we do before we begin to code?  Waterfall: Design it all! (slight exaggeration… but not much)  Agile:"

Similar presentations


Ads by Google