Skip to content

Commit c5edda8

Browse files
committed
[doc] cppnow-2017
1 parent 158b6e8 commit c5edda8

File tree

1 file changed

+109
-34
lines changed

1 file changed

+109
-34
lines changed

docs/cppnow-2017/index.html

Lines changed: 109 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109

110110
----
111111

112-
##Costs associated with First-Class Tests
112+
##Cost per defect and First-Class Tests
113113

114114
![cost_testing](images/cost_testing.png)
115115

@@ -367,8 +367,8 @@
367367
```cpp
368368
"should read 42"_test = [] {
369369
MockReader reader{};
370-
// At least we can use the same front-end
371370
371+
// At least we can use the same front-end
372372
EXPECT_CALL(reader, read).WillOnce(Return(42));
373373
374374
read(reader);
@@ -520,7 +520,7 @@
520520
} {}
521521
522522
template <class TName, class R, class... TArgs>
523-
auto call(TArgs&&... args) {
523+
auto call_(TArgs&&... args) {
524524
return poly_.virtual_(TName{})(poly_, args...);
525525
}
526526
@@ -653,7 +653,7 @@
653653
};
654654
```
655655

656-
#### We can only do Integration-tests or black box tests here!
656+
#### We can only do Integration-testing or black box testing here!
657657

658658
----
659659

@@ -690,6 +690,14 @@
690690
}; };
691691
```
692692

693+
```cpp
694+
class Reader final class Printer final
695+
: public IReader { : public IPrinter {
696+
public: public:
697+
int read() override; void print(int) override;
698+
}; };
699+
```
700+
693701
----
694702

695703
### <strike>Stupid</strike> vs SOLID
@@ -720,10 +728,11 @@
720728

721729
```cpp
722730
"should print read value"_test = [] {
723-
NiceGMock<ILogger> logger{}; // ignore an uninteresting call
724-
StrictGMock<IReader> reader{}; // fail on uninteresting call
725-
StrictGMock<IPrinter> printer{}; // fail on uninteresting call
726-
App app{reader, printer, logger}; // wiring!
731+
// Some boilerplate introduced!
732+
NiceGMock<ILogger> logger{}; // Ignore an uninteresting call
733+
StrictGMock<IReader> reader{}; // Fail on uninteresting call
734+
StrictGMock<IPrinter> printer{}; // Fail on uninteresting call
735+
App app{reader, printer, logger}; // Wiring!
727736
728737
EXPECT_CALL(reader, read).WillOnce(Return(42));
729738
EXPECT_CALL(printer, print, 42);
@@ -790,9 +799,9 @@
790799

791800
```cpp
792801
"should print read value"_test = [] {
793-
NiceGMock<Loggable> logger{}; // ignore an uninteresting call
794-
StrictGMock<Readable> reader{}; // fail on uninteresting call
795-
StrictGMock<Printable> printer{}; // fail on uninteresting call
802+
NiceGMock<Loggable> logger{}; // Ignore an uninteresting call
803+
StrictGMock<Readable> reader{}; // Fail on uninteresting call
804+
StrictGMock<Printable> printer{}; // Fail on uninteresting call
796805
App app{reader, printer, logger}; // C++17 template argument
797806
// deduction for class templates
798807
@@ -806,7 +815,7 @@
806815

807816
----
808817

809-
### App - Type-Erasure - Virtual Concepts
818+
### App - Type-Erasure - Virtual Concepts (Dynamic Dispatch without inheritance)
810819

811820
```cpp
812821
class App {
@@ -831,9 +840,9 @@
831840
### App - Unit-Testing - Type-Erasure
832841
```cpp
833842
"should print read value"_test = [] {
834-
NiceGMock<Loggable> logger{}; // ignore an uninteresting call
835-
StrictGMock<Readable> reader{}; // fail on uninteresting call
836-
StrictGMock<Printable> printer{}; // fail on uninteresting call
843+
NiceGMock<Loggable> logger{}; // Ignore an uninteresting call
844+
StrictGMock<Readable> reader{}; // Fail on uninteresting call
845+
StrictGMock<Printable> printer{}; // Fail on uninteresting call
837846
App app{reader, printer, logger}; // C++17 template argument
838847
// deduction for class templates
839848
@@ -847,11 +856,11 @@
847856

848857
----
849858

850-
### Are there any problems with `SOLID` approach?
859+
### So far so good, but are there any problems with `SOLID` approach?
851860
852861
----
853862
854-
### Manual Dependency Injection - Wiring Mess
863+
### Wiring Mess
855864
856865
> `SOLID` allows testable design but it moves the problem to the caller!
857866
@@ -1168,9 +1177,10 @@
11681177
###Automatic mocks injection - How?
11691178
11701179
```cpp
1180+
template<class TArgs, class TMocks>
11711181
struct mocker {
1172-
mocks_t& mocks;
1173-
args_t& args;
1182+
const TArgs& args;
1183+
TMocks& mocks;
11741184

11751185
template<class T, REQUIRES(std::is_polymorphic<raw_t<T>>{})>
11761186
operator T() const {
@@ -1200,7 +1210,7 @@
12001210
12011211
----
12021212
1203-
### Okay, that's fancy, but how testable code might be produced by default?
1213+
### Okay, that's fancy, but how it can be used to produce a testable code by default?
12041214
12051215
### Solution -> Test Driven Development
12061216
@@ -1472,7 +1482,7 @@
14721482
### BDD/RED - Write a bit of test
14731483
14741484
```cpp
1475-
"[0.0.1] Parse feeds [empty stream of feeds]"_test = [] {
1485+
"[0.0.1] Parse feeds [should connect on start]"_test = [] {
14761486
GIVEN("A trading system",
14771487
auto [ts, mocks] = testing::make<trading_system>()
14781488
);
@@ -1485,7 +1495,7 @@
14851495
14861496
----
14871497
1488-
### BDD/GREEN - Make it pass
1498+
### BDD/GREEN - Make it compile/pass (The simplest way)
14891499
14901500
```cpp
14911501
template<class TMarketData = Streamable(class MarketData)>
@@ -1523,16 +1533,15 @@
15231533
15241534
----
15251535
1526-
### BDD/GREEN - Make it pass
1536+
### BDD/GREEN - Make it pass again...
15271537
15281538
```cpp
15291539
template<...>
15301540
class trading_system {
15311541
public:
15321542
...
15331543
void process() {
1534-
auto buffer = marketData.read();
1535-
if (buffer.empty()) {
1544+
if (auto buffer = marketData.read(); buffer.empty()) {
15361545
marketData.disconnect();
15371546
}
15381547
}
@@ -1545,6 +1554,81 @@
15451554
15461555
----
15471556
1557+
#### 1. TDD/RED - Write a bit of test (expectations/intentions)
1558+
1559+
```cpp
1560+
"should connect to the stream on creation"_test = [] {
1561+
auto [fh, mocks] = testing::make<feed_handler()>(mocks);
1562+
EXPECT_CALL(mocks<Streamable>(), connect);
1563+
fh(); // create feed_handler
1564+
};
1565+
```
1566+
1567+
----
1568+
1569+
#### 2. TDD/GREEN - Make it compile/pass (the simpler way)
1570+
1571+
```cpp
1572+
template<class TStream = Streamable>
1573+
class feed_handler {
1574+
public:
1575+
explicit feed_handler(TStream& stream) {
1576+
stream.connect();
1577+
}
1578+
};
1579+
```
1580+
1581+
----
1582+
1583+
## TDD and eXtreme programming / Pairing
1584+
1585+
<img src="images/pair.png" width="85%" />
1586+
1587+
> 1. One dev is writing a test and the other is making it pass (the simplest way)
1588+
> 2. Switch the roles!
1589+
1590+
----
1591+
1592+
#### 1. TDD/RED - Write another test
1593+
1594+
```cpp
1595+
"should disconnect when read an empty stream"_test = [] {
1596+
auto [fh, mocks] = testing::make<feed_handler()>();
1597+
1598+
InSequence sequence;
1599+
EXPECT_CALL(mocks<Streamable>(), connect());
1600+
EXPECT_CALL(mocks<Streamable>(), read()).WillOnce(Return(""));
1601+
EXPECT_CALL(mocks<Streamable>(), disconnect());
1602+
1603+
EXPECT(not fh().process());
1604+
};
1605+
```
1606+
1607+
----
1608+
1609+
#### 2. TDD/GREEN - Make all tests pass
1610+
1611+
```cpp
1612+
template<class TStream = Streamable>
1613+
class feed_handler {
1614+
public:
1615+
explicit feed_handler(TStream& stream) {
1616+
stream.connect();
1617+
}
1618+
1619+
auto process() {
1620+
if (auto buffer = stream.read(); buffer.empty()) {
1621+
stream.disconnect();
1622+
return false;
1623+
}
1624+
return true;
1625+
}
1626+
1627+
private:
1628+
TStream& stream;
1629+
};
1630+
```
1631+
15481632
----
15491633
15501634
### Commit
@@ -1580,15 +1664,6 @@
15801664
15811665
----
15821666
1583-
## TDD and eXtreme programming / Pairing
1584-
1585-
<img src="images/pair.png" width="85%" />
1586-
1587-
> 1. One dev is writing a test and the other is making it pass (the simplest way)
1588-
> 2. Switch the roles!
1589-
1590-
----
1591-
15921667
<img style="background:none; border:none; box-shadow:none;" src="images/done.png" />
15931668
15941669
* #### Take the next story...

0 commit comments

Comments
 (0)