Page 1
Doug BradburySoftware Craftsman, 8th Light
Acceptance TestingHow CSlim and FitNesse Can Help You Test Your Embedded System
Page 2
Tutorial Environment
git clone git://github.com/dougbradbury/c_learning.gitcd c_learning./bootstrap.sh
or with a live CD:cp -R cslim_agile_package c_clearningcd c_learninggit pull./bootstrap.sh
Page 3
OverviewTalk w/ exercises: Acceptance Tests
Tutorial: Writing Acceptance tests
Tutorial: Fitnesse
Tutorial: CSlim
Talk: Embedded Systems IntegrationBonus Topics
Page 4
IntroductionsWho are you?Where do you work?What experience do you have with ...
embedded systems?acceptance testing?FitNesse and Slim?
Page 5
ObjectivesAs a result of this course you will be able to:
Understand the purposes of acceptance testing;
Use acceptance tests to define and negotiate scope on embedded systems projects;
Integrate a CSlim Server into your embedded systems;
Page 6
Objectives (cont)As a result of this course you will be able to:
Add CSlim fixtures to your embedded system;
Write Fitnesse tests to drive the execution of CSlim fixtures;
Write and maintain suites of tests in a responsible manner.
Page 7
Points on a starHow many points does this star have?
Page 8
Star Point SpecificationPoints on a star are counted by the number of exterior points.
Page 9
Points on a starHow many points does this star have?
Page 11
Points on a starNow, how many points does this star have?
Page 12
Robo-drawPick a partner ...
Page 13
Acceptance TestingCollaboratively producing examples of what a piece of software is supposed to do
Page 14
Unit Testshelp you build the code right.
Acceptance Testshelp you build the right code.
Page 15
Acceptance TestsA collaborative derivation of scope
Page 16
Acceptance TestLiving Documentation
Page 17
Acceptance TestA medium for communication
Page 18
Acceptance Tests
Tests
Page 19
Acceptance Tests
Tests
Page 20
Acceptance Tests
Entire System
Page 21
Acceptance Tests
Entire System
Page 22
FailDon’t test the entire system
Page 23
Acceptance Tests
User Interface
Page 24
Acceptance Tests
User Interface
Page 25
Acceptance Tests
Load / Performance
Page 26
Acceptance Tests
Load / Performance
Page 27
Acceptance Tests
Hardware
Page 28
Acceptance Tests
Hardware
Page 29
Acceptance Tests
Algorithm
Page 30
Acceptance Tests
Algorithm
Page 31
Acceptance Tests
QA Tool
Page 32
Acceptance Tests
QA Tool
Page 33
Acceptance Tests
Collaboratively produced examples
A definition of scope
Living documentation
A medium for communication
Page 34
Why you really need ATsТвой софт - говно!
Page 35
Why you really need ATsТвой софт - говно!
Page 36
Workflow TestsGiven, When, ThenPreconditions, Action, Results
Page 37
Workflow exampleGiven a new car traveling at 30 mphWhen I fully apply the breaksThen the car should stop within 35 yards
Page 38
An example, by exampleA treadmill controller
walkncode.com
Page 39
Treadmill RequirementsIt controls the speed of the treadmill.
It increments and decrements the speed.
The max speed is configurable.
It keeps track of total distance walked.
It keeps track of calories burned.
Page 41
Ambiguitiesmph, kph, fps?inc dec amounts?range for max speed?distance in miles, km?formula for tracking calories?
Page 42
Treadmill by exampleGiven treadmill speed is 1.0 mphWhen I increment the speedThen the speed should be 1.1 mph
Page 43
Your Turn Write an example for the decrement speed
scenario.
Write an example for the max speed scenario
Page 44
Decrement SpeedGiven treadmill speed is 1.0 mphWhen I decrement the speedThen the speed should be 0.9 mph
Page 45
Maximum SpeedGiven treadmill speed is 3.0 mphGiven max speed is 3.0 mphWhen I increment the speedThen the speed should be 3.0 mph
Page 46
Calculation TestsA series of inputs and outputsUsually captured in table form
Page 47
Division Test
numerator denominator quotient?
10 5 2
39 3 13
5 2 2.5
Page 48
Calories Burned Test
speed time calories?
1.0 60 70
2.0 60 150
3.0 60 220
Page 49
Your TurnWrite a calculation example for distance traveled.
Page 50
Distance Travelled
speed time distance?
1.0 30 0.5
2.0 30 1.5
1.5 60 3.0
Page 51
Cumulative Distance
speed time distance?
1.0 30 0.5
2.0 30 1.0
1.5 60 1.5
Page 52
When Do you stop?
Page 53
Break
git clone git://github.com/dougbradbury/c_learning.gitcd c_learning./bootstrap.sh
or with a live CD:cp -R cslim_agile_package c_learningcd c_learninggit pull./bootstrap.sh
Page 54
FitNesse Ecosystem
Page 55
Starting FitNessejava -jar fitnesse.jar -p 8080 -e 0
OptionsPort: -p 8080No History: -e 0
Page 56
FitNesse TutorialFollow along!
Page 58
Editing a pageTry typing a WikiWord (at least 2 capital letters) - Then save
Page 59
Creating a new pageClick on the ‘?’ to create that new page
Page 60
Editing a new page
Page 61
TablesTables in FitNesse are defined with pipes ‘|’
Page 62
TablesSave your table
Page 63
User GuideLearn more about the wiki markup language
Page 64
Let’s write someexamples
Page 65
Another way to add pages
Page 66
Three types of pagesNormal - Contain only text and linksTest - Executable pagesSuite - a SubWiki of tests (or other suites)
Page 67
Let’s view the new test
Page 68
Test PagesBehold, the test button
Page 69
Calculation TestEdit this test and create a decision table
Page 70
Push the button!Green means passed
Page 71
Try some other valuesRed means failure
Page 72
Line up your columnsTry the “format” button
Page 73
Workflow TestCreate a new test with a script table
Page 74
Workflow Test Run
Page 76
ExerciseCreate a TreadmillSuiteCreate the following tests
TestIncrementTreadmill (workflow)TestDecrementTreadmill (workflow)TestMaxSpeed (workflow)TestCumulativeDistance (calculation)TestTotalDistance (calculation)
Page 82
It’s Fixture Timecslim/fixtures/Fixtures.c
Page 83
It’s Fixture Timecslim/fixtures/DecisionTableExample.c
Page 84
Fixture “Objects”cslim/fixtures/DecisionTableExample.c
Page 85
Fixture functionscslim/fixtures/DecisionTableExample.c
Page 86
SlimListcslim/include/CSlim/SlimList.h
Page 87
Returning a Valuecslim/fixtures/DecisionTableExample.c
All return values are strings.
Page 88
Extra functionsDecision tables have a few optional functions.
Page 89
Order of Executionall settersexecute()all gettersreset()
Page 90
Let’s build a fixtureCheatSuite.TreadmillControlSuite
Page 91
TestIncrementSpeedExceptions are yellow
Page 92
TestIncrementSpeedLet’s create a fixture called “Treadmill”
Page 93
Create a Fixturecd treadmill/fixtures/cp FixtureTemplate.c Treadmill.csed -i '' s/ExampleFixture/Treadmill/g Treadmill.c
Page 94
Register the Fixturefixtures/Fixtures.c
Page 95
ReBuild the ‘at’ target%> make at
Page 96
Run the Test againFixture was found!
Page 97
The First MethodgivenTreadmillSpeed
Page 98
The First Methodtreadmill/fixtures/Treadmill.c
Page 99
IncrementSpeedImplement Increment Speed on your own.
Page 100
targetSpeedReturn a value to make the test fail.
Page 101
targetSpeed Failure
Page 102
Treadmill Apiinclude/treadmill/Api.h
Page 103
Declare an instancetreadmill/fixtures/Treadmill.c
Page 104
Create & Destroytreadmill/fixtures/Treadmill.c
Page 105
Reading from a SlimListtreadmill/fixtures/Treadmill.c
Page 106
No Parameterstreadmill/fixtures/Treadmill.c
Page 107
Resulttreadmill/fixtures/Treadmill.c
Page 108
ReBuild the ‘at’ target%> make at
Page 109
Woot!Green is good
Page 110
ExerciseAdd fixture methods to Treadmill.c to support:
TestDecrementSpeed TestMaxSpeed
Page 111
Catch upIf you need to catch up with the group
cp cheat_fixtures/Treadmill.c fixtures
Page 112
Calculation Test
Page 113
Create a new fixturecd treadmill/fixtures/cp FixtureTemplate.c TreadmillCumulativeDistance.csed -i '' s/ExampleFixture/TreadmillCumulativeDistance/g TreadmillCumulativeDistance.c
Page 114
Decision table namingspeed => setSpeedtime => setTimedistance? => distance
Page 115
Make it red.Implement stubs for:setTimesetSpeeddistance
Page 116
Does anybody reallyknow what time it is?
We will use a link-time seam to mock out uptime.
include/hardware/Uptime.h
Page 117
FakeUptime
mocks/hardware/FakeUptime.c
mocks/hardware/FakeUptime.h
Page 118
Back to our fixtureUse the uptimeMillis extern to set the current time
fixtures/TreadmillCumulativeDistance.c
Page 119
ExerciseFinish the TreadmillCumulativeDistance fixture.Extra credit: TreadmillDistance fixture. (hint: you’ll need to use the reset function)
Page 120
Cumulative Distance fixtures/TreadmillCumulativeDistance.c
Page 121
Cumulative Distance fixtures/TreadmillCumulativeDistance.c
Page 122
Cumulative Distance fixtures/TreadmillCumulativeDistance.c
Page 123
Cumulative Distance fixtures/TreadmillCumulativeDistance.c
Page 124
Total Distance fixtures/TreadmillDistance.c
Page 126
System Architecture
Domain API
Application
Web App
Message Protocol
Hardware
Front Panel
Hardware Abstraction
Fixtures
Mock HW
Production Build
AT build
Page 127
System Architecture
Domain API
Application
Web App
Message Protocol
Hardware
Front Panel
Hardware Abstraction
Fixtures
Mock HW
Production Build
AT build
Page 128
Hardware AbstractionRemember, acceptance tests are not about testing the hardware.
Page 129
Hardware Abstraction include/hardware/Pwm.h
4 void Pwm_Create(void); 5 void Pwm_Destroy(void); 6 7 void Pwm_Start(); 8 void Pwm_Stop(); 9 void Pwm_SetDutyCycle(double percent); 10 void Pwm_SetPeriod(int microseconds);
Page 130
mocks/hardware/FakePwm.h
4 #include "Pwm.h" 5 6 extern int FakePwm_isRunning; 7 extern int FakePwm_period; 8 extern double FakePwm_dutyCycle;
Hardware Abstraction
Page 131
mocks/hardware/FakePwm.c
3 int FakePwm_isRunning = 0; 4 double FakePwm_dutyCycle = 0.0; 5 int FakePwm_period = 0; 6 11 void Pwm_Start(void) { FakePwm_isRunning = 1; } 13 void Pwm_Stop(void) { FakePwm_isRunning = 0; } 15 void Pwm_SetDutyCycle(double percent) { FakePwm_dutyCycle = percent; } 17 void Pwm_SetPeriod(int us) { FakePwm_period = us; }
Hardware Abstraction
Page 132
UI abstractionThe UI uses the same API as the tests
Click /Press
Page 133
UI abstractionThe UI uses the same API as the tests
Click /Press
Page 134
UI AbstractionDetect button press ...
Api_IncrementTargetSpeed();
....
Page 135
UI AbstractionWhat about Displays?
LCD
Application
Page 136
UI AbstractionWhat about Displays?
LCD
Application
Page 137
UI AbstractionTurn the dependency around with an observer
Application
LCD
Page 138
UI AbstractionObserver Pattern
void onSpeedChange(double speed) {/*update speed display */}
Api_registerSpeedObserver(&onSpeedChange);
Page 139
MessagingUses the same API as everyone else.
Test message parsing independently.
Page 140
TimersCan’t wait on real time
Timer also hit the same API
Page 141
InterruptsGenerate events in system that can be simulated
Page 142
Then what’s the point?Acceptance tests are not entire system tests.
They are a software collaboration medium.
Page 143
Running on target
Page 144
Serial BridgeWhat about running on a target without anethernet stack?
https://github.com/dougbradbury/slim_bridge
Page 145
Running on target
Fitnesse Slim Bridge Slim Server
hostprocessor
embeddedtarget
TCP Serial
Page 148
Porting CSlimImplement a TCP socket Server
only needs to handle one connection at a time
calls Slim_HandleConnection with pointers to send / recv functions
Page 149
You can helpStill some features missing (sut, libraries)
Contribute your port back to the project
Help reduce memory usage
Slim(mer)?
Page 150
Bonus topicsMulti-parameter script table functionsReturning ListsQuery tables
Page 151
Multiple ParametersFunction name alternates with parameters
Page 152
Multiple ParametersFunction name alternates with parameters
Page 153
Multiple ParametersFunction name alternates with parameters
Page 154
Returning Listscslim/fixtures/QueryTableExample
. . .
Page 155
Query TablesRows of RecordsOrder doesn’t matter
Page 156
Query TablesReturn a List of recordsA record is a list or key, value pairsA key, value pair is a two element list
(((id, 1), (pay, 1000))((id 2), (pay, 1500))
)
Page 157
Query TablesThe list must be serialized and returned from the query function.
cslim/fixtures/QueryTableExample.c
Page 158
Recommended ReadingSpecification by Example - Gojko Adzic
Test Driven Development for Embedded C - James Grenning
Fit - For Developing Software - Mugridge / Cunningham
FitNesse Users Guide
Page 159
Contact Info@dougbradbury
[email protected]