Test driven development for Invisible Hardware Samuel Gaist - - PowerPoint PPT Presentation

test driven development for invisible hardware
SMART_READER_LITE
LIVE PREVIEW

Test driven development for Invisible Hardware Samuel Gaist - - PowerPoint PPT Presentation

Test driven development for Invisible Hardware Samuel Gaist Edeltech Ltd Switzerland jeudi, 9 octobre 14 Samuel Gaist Software Development Engineer Partner at Edeltech Ltd Developer at IDIAP Research Institute Qt Experience User


slide-1
SLIDE 1

Test driven development for Invisible Hardware

Samuel Gaist Edeltech Ltd Switzerland

jeudi, 9 octobre 14

slide-2
SLIDE 2

Samuel Gaist

Software Development Engineer

  • Partner at Edeltech Ltd
  • Developer at IDIAP Research Institute

Qt Experience

  • User since Qt 3.2
  • Contributor for ~ 2 years (QtCore, QtGui, QtMacExtras)
  • 10’000+ posts in Qt Forum

2

jeudi, 9 octobre 14

slide-3
SLIDE 3

Outline

  • 1. AgiScan, a film scanning application
  • 2. Invisible Devices
  • 3. Test Driven Development with Invisible Devices
  • 4. Demo
  • 5. Wrap Up
  • 6. Q/A

jeudi, 9 octobre 14

slide-4
SLIDE 4
  • 1. AgiScan, a film scanning application

Embedded App Proprietary Qt Desktop App Mac OS / Windows

USB Audio/Video

jeudi, 9 octobre 14

slide-5
SLIDE 5
  • 1. AgiScan, a film scanning application

jeudi, 9 octobre 14

slide-6
SLIDE 6
  • 1. AgiScan, a film scanning application

The Application (AgiScan) requires the device (Film scanner).

  • to setup the GUI since the App supports different scanner

models with different hardware options.

  • to setup the audio and video capture subsystems since

each scanner model produces different resolutions, image formats, etc…

jeudi, 9 octobre 14

slide-7
SLIDE 7
  • 2. Invisible Devices
  • It can’t be moved next to your desk.

because it’s too big or heavy

  • It doesn’t exist yet.

next week, promised

  • It exists but you can’t have it.

because someone needs it or it’s too expensive

  • The only one we have has been sold yesterday.

we’ll build you a new one if we get an order…

200k€

200kg

jeudi, 9 octobre 14

slide-8
SLIDE 8
  • 2. Invisible Devices

I can’t have one = INVISIBLE So how do I develop my Application ?

jeudi, 9 octobre 14

slide-9
SLIDE 9
  • 3. Test Driven Development with

Invisible Devices

Write a Mock Object

to mimic the behaviour of the Invisible Device in controlled ways.

jeudi, 9 octobre 14

slide-10
SLIDE 10
  • 3. Test Driven Development with

Invisible Devices

Use an Adapter Object

to communicate with the device when it is available,

  • r with the Mock Object.

jeudi, 9 octobre 14

slide-11
SLIDE 11
  • 3. Test Driven Development with

Invisible Devices

Apply TDD principles

because we want to sleep well.

jeudi, 9 octobre 14

slide-12
SLIDE 12
  • 3. Test Driven Development with

Invisible Devices

Run Test (Re-)Write a Test Run all Tests Write Code Refactor / Clean Code

PASS FAIL FAIL PASS

TDD Friendly Reminder

http://en.wikipedia.org/wiki/Test-driven_development

jeudi, 9 octobre 14

slide-13
SLIDE 13
  • 3. Test Driven Development with

Invisible Devices

TDD Benefits

  • 1. Know how your code works.
  • 2. Know that your code works.
  • 3. Help other developers understand your code.
  • 4. Know when you break something.

jeudi, 9 octobre 14

slide-14
SLIDE 14

Levels of testing

UNIT TEST Each class, e.g. the Mock Object FUNCTIONAL TEST Several classes, e.g. Mock Object + Adapter SYSTEM TEST Application: e.g. Scenario based user interaction, Squish

14

  • 3. Test Driven Development with

Invisible Devices

jeudi, 9 octobre 14

slide-15
SLIDE 15

15

  • 3. Test Driven Development with

Invisible Devices

Project Architecture

jeudi, 9 octobre 14

slide-16
SLIDE 16

#include <QtTest> #include <QCoreApplication> #include "mycoolclass.h" class UnitTestMyCoolClass : public QObject { Q_OBJECT private Q_SLOTS: void testCase1(); }; QTEST_MAIN(UnitTestMyCoolClass); #include “tst_UnitTestMyCoolClass.moc”

16

  • 3. Test Driven Development with

Invisible Devices

Using QTest

jeudi, 9 octobre 14

slide-17
SLIDE 17

17

  • 3. Test Driven Development with

Invisible Devices

Let’s write a unit test.

jeudi, 9 octobre 14

slide-18
SLIDE 18

18

  • 3. Test Driven Development with

Invisible Devices

Know your Device

  • 1. What interface does it provide ?

Serial Port, Network, …

  • 2. What is the communication protocol ?

Commands, Responses

To write the Mock Object.

jeudi, 9 octobre 14

slide-19
SLIDE 19

19

The Mock Object

#include <QObject> class MockDevice : public QIODevice { Q_OBJECT public: MockDevice(); protected: qint64 readData(char *data, qint64 maxlen) Q_DECL_OVERRIDE; qint64 writeData(const char *data, qint64 len) Q_DECL_OVERRIDE; };

  • 3. Test Driven Development with

Invisible Devices

jeudi, 9 octobre 14

slide-20
SLIDE 20

20

  • 3. Test Driven Development with

Invisible Devices

Define the Controller API

  • 1. How will the application interact with

the controller ?

Signal/Slots, Events, other ?

  • 2. Level of abstraction

Map the “device lingo” to sensible methods / properties.

To write the Adapter Object.

jeudi, 9 octobre 14

slide-21
SLIDE 21

21

#include <QObject> class Controller : public QObject { Q_OBJECT public: Controller(QObject *parent = 0); void setDevice(QIODevice *device); public Q_SLOTS: void doSomething(); void doSomethingElse(); private: QIODevice *_device; }; void Controller::doSomething() { _device->write(DoSomethingCommand); }

QIODevice

QBuffer, QSocket, QSerialPort…

The Adapter Object

  • 3. Test Driven Development with

Invisible Devices

jeudi, 9 octobre 14

slide-22
SLIDE 22

22

  • 3. Test Driven Development with

Invisible Devices

Let’s write a controller and test it.

jeudi, 9 octobre 14

slide-23
SLIDE 23

23

  • 3. Test Driven Development with

Invisible Devices

Detect the actual device

Using an enumerator (Bonjour, QSerialPortInfo)

Write a Factory

to return the Actual Device or the Mock Device.

and pass it to your Controller using ::setDevice(QIODevice*)

jeudi, 9 octobre 14

slide-24
SLIDE 24

24

  • 4. Demo

Demo

jeudi, 9 octobre 14

slide-25
SLIDE 25

25

  • 5. Wrap up
  • Using a Mock Device we can develop an application controlling a

device without the actual hardware.

  • The Tests ensure that the Mock Device and the Application work

correctly, and allow developers to reproduce bugs occurring with the actual hardware.

  • The Mock Device can be used to create a Demo Mode.

jeudi, 9 octobre 14

slide-26
SLIDE 26

Q/A

Questions ?

26

jeudi, 9 octobre 14