Agile Modeling and TDD Workshop, by Craig Larman (3)

Having pseudo-acceptance-tests on the wall, it’s time to realize them now. The test automation framework we used was www.robotframework.org. which is a keyword-driven framework for acceptance tests in tabular format.

Acceptance Test Driven Development (ATDD) practice drives development from automated acceptance tests, those executable acceptance tests. After written those pseudo tests into Robot format, we got a red FAIL of execution, since there was no keywords nor production code.

One test my pair created was :

Robot Test Cases

Setting

Value

Library

MonopolyLibrary
Test Case

Action

IN:
rounds

IN:
Players

Post Condition:
Actual Rounds

Post Condition:
All Pieces Current Square

Post Condition:
game Stop

Post Condition:
Output Trace

Test1

Run The Game And Check Post Conditions

${2}

${2}

${2}

NOT goSquare

TRUE

NOT NULL

Test2

Run The Game And Check Post Conditions

${17}

${2}

${17}

TRUE

NOT NULL
Keyword

Action

Argument

Argument

Argument

Argument

Argument

Argument

Run The Game And Check Post Conditions

[Arguments]

${rounds}

${players}

${actual rounds}

${all pieces current square}

${game stop}

${output trace}

Init The Game

${rounds}

${players}


Run The Game


${testReturn}

Get Actual Rounds


Should Be Equal

${actualRounds}

${testReturn}

Next step was natually implementing the feature, and we also follow the unit level TDD. Java was used, and Eclipse, the refactoring feature was really nice, easy to move values out to be a variable, or extract a method from duplicated lines of code. Write code only when you have a failling test! Before write a test, you could use Agile modeling to design.

* Activity Diagram is a loosely defined diagram technique for showing workflows of stepwise activities and actions, with support for choise, iteration and concurrency. It’s useful for design of algorithms. While the System Sequence Diagram identifies each system operation for which we need to design a solution.

* Communication Diagram models the interactions between objects or parts in terms of sequenced messages.

It always worth reflection / inspiration from other models, e.g. activity diagram, system sequence diagram and so on. I haven’t took the picture, but if you could see all those on the wall clearly and clustered, you’ll fell the amaze.

* Class Diagram is a type of static structure diagram that describes the structure of a system by showing the system’s classes, their attributes, and the relationships between the classes.

Ok! Time for coding now!

Let’s pair!

Project is not essential, the reason we used is three people were in a group, we need a way to share, notebook screen was too small.

The pair proceeded according to ATDD cycle, have a failed acceptance test, start to design, write a failed unit test, fill in code to satisfy the failed unit test, refactor when needed, and so on.

A fairly good thing was having the "design wall" close to pair programming notebook, whenever there was some new ideas or abnormal signals from code, we discussed and updated either the design or the code, keep them up-to-understanding. Very frequent updates happened all along this pair session, we quickly draw our design on the wall, and update or even erase it totally and draw a new one. The erasable plastic paper was really great, without any tapes, it could be pasted on the wall just by the power of static (static electricity?).

Finally here were some unit tests and code for your reference :

* BoardTest.java

package monopoly;


import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

public class BoardTest {
private Board board;

@Before
public void setUp() {
board = new Board();
}

@Test
public void startsFromSquareOne() throws Exception {
Square square = board.getStartingSquare();
assertEquals("1", square.getName());
}

@Test
public void movesToNextSquareAccordingToFaceValue() throws Exception {
Square startingSquare = board.getStartingSquare();

Square nextSquare = board.getNewSquare(startingSquare, 1);
assertEquals("2", nextSquare.getName());

nextSquare = board.getNewSquare(startingSquare, 7);
assertEquals("8", nextSquare.getName());
}

@Test
public void willPassStartingSquareAfterFullBoardRound() throws Exception {
Square currentSquare = board.getStartingSquare();
for (int i = 0; i < 4; i++) {
currentSquare = board.getNewSquare(currentSquare, 12);
}

assertEquals("9", currentSquare.getName());
}
}

* Board.java

package monopoly;

public class Board {
private static final int MAX_NUMBER_OF_SQUARES = 40;

public Square getNewSquare(final Square currentSquare, final int dieFaceValue) {
int nextNumber = calculateNextSquare(currentSquare, dieFaceValue);
return createSquare(nextNumber);
}

public Square getStartingSquare() {
return createSquare(1);
}

private Square createSquare(int nextNumber) {
return new Square("" + nextNumber);
}

private int calculateNextSquare(final Square currentSquare, final int dieFaceValue) {
int nextNumber = handleCircumnambulation(Integer.parseInt(currentSquare.getName()) + dieFaceValue);
return nextNumber;
}

private int handleCircumnambulation(int nextNumber) {
if (nextNumber > MAX_NUMBER_OF_SQUARES) {
nextNumber -= MAX_NUMBER_OF_SQUARES;
}
return nextNumber;
}
}

References :
– Experience comes from the workshop facilitated by Craig Larman, his website is http://www.craiglarman.com.
– Explanation of many terms come from http://www.wikipedia.org.
– Test Automation framework used is robotframework.
– Programming tool used is eclipse.

About Kaveri, Yi XU

Agile Coach & Consutlant
This entry was posted in Agile&Scrum&Testing&TA. Bookmark the permalink.

3 条 Agile Modeling and TDD Workshop, by Craig Larman (3) 的回复

  1. Shiquan说道:

    o, the picture is blur, and the craft is difficult to recognize, so i can only get some basic concept.

  2. Shiquan说道:

    but this series is great

  3. Yi说道:

    you’ll learn it via inspect and adapt🙂

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s