-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
990 lines (810 loc) · 30.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JGiven</title>
<meta name="description" content="Behavior-Driven Development in Plain Java">
<meta name="author" content="Jan Schäfer">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/white.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="lib/css/github-gist.css">
<link rel="stylesheet" href="css/fonts/font-awesome.min.css">
<link rel="stylesheet" href="css/fonts.css">
<link rel="stylesheet" href="css/custom.css">
<link rel="stylesheet" href="css/gh-fork-ribbon.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<section class="title">
<h1>JGiven: Pragmatic BDD for Java</h1>
<h2 style="margin-top:60px; margin-bottom: 40px; color: #444">Dr. Jan Schäfer</h2>
<a href="http://tngtech.com"><img style="margin-bottom:20px; margin-top:0px; height:40px;" src="img/tng.svg" /></a>
<h3>Sep 20, 2016</h3>
<h4>JavaOne</h4>
<!-- <img style="background-color: #2d5352; padding: 10px;" width="150" src="img/ETka-Logo.png" /> -->
</section>
</section>
<section>
<section>
<h1>Why BDD?</h1>
<aside class="notes">
</aside>
</section>
<section>
<a target="_blank" href="http://localhost:9967/petclinic/">
<img src="img/petclinic.png" />
</a>
</section>
<section>
<h2>Typical Test</h2>
<aside class="notes">
Kann nicht zur Kommunikation mit Domain-Experten genutzt werden<br />
Carola und Henning: Minimal viable product: Muss als Testfall formuliert werden können
</aside>
<pre><code data-trim style="font-size:16px; line-height:1.2">
@Test
public void shouldInsertPetIntoDatabaseAndGenerateId() {
Owner owner6 = this.clinicService.findOwnerById(6);
int found = owner6.getPets().size();
Pet pet = new Pet();
pet.setName("bowser");
Collection<PetType> types = this.clinicService.findPetTypes();
pet.setType(EntityUtils.getById(types, PetType.class, 2));
pet.setBirthDate(new DateTime());
owner6.addPet(pet);
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
this.clinicService.savePet(pet);
this.clinicService.saveOwner(owner6);
owner6 = this.clinicService.findOwnerById(6);
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
// checks that id has been generated
assertThat(pet.getId()).isNotNull();
}
</code></pre>
<small>Example from <a href="https://github.com/spring-projects/spring-petclinic">github.com/spring-projects/spring-petclinic</a></small>
<!-- <img src="img/tdd.svg"> -->
</section>
<section>
<h2>Issues with typical JUnit tests</h2>
<ul class="fa-ul bad">
<li class="fragment">Many technical and irrelevant details</li>
<li class="fragment">Point of the test often hard to grasp</li>
<li class="fragment">Code duplication</li>
<li class="fragment"><b>Can only be read by developers</b></li>
</ul>
</section>
<section>
<h2>Behavior-Driven Development</h2>
<ul>
<li>Tests are written as <b>Scenarios</b></li>
<li>Scenarios are written in a common <b>domain language</b> understandable by business owners</li>
<li>Typically in the Given-When-Then format</li>
</ul>
<aside class="notes">
Working software over comprehensive documentation
</aside>
</section>
<section>
<h2>Example</h2>
<pre><code class="gherkin" data-trim>
Scenario: Pets can be assigned to pet owners
Given a pet owner
And a dog
When assigning the pet to the pet owner
Then the pet owner owns an additional pet
</code></pre>
</section>
<!--
<section>
<h2>TDD</h2>
<h3>Bauen wir die Anwendung richtig?</h3>
<p><h3> </h3></p>
<h2>BDD</h2>
<h3>Bauen wir die richtige Anwendung?</h3>
-->
<!--
<section>
<h2>Example</h2>
<pre><code class="gherkin" data-trim>
Scenario: new pets can be assigned to existing owners
Given an existing pet owner
And a new pet
When the pet is assigned to the owner
Then the pet exists in the system
And the pet belongs to the owner
</code></pre>
</section>
<section data-transition="fade-in fade-out">
<h2>Behavior-Driven Development</h2>
<img src="img/bddraw.svg">
</section>
<section data-transition="fade-in slide-out">
<h2>Behavior-Driven Development</h2>
<img src="img/bddkommunikation.svg">
</section>
</section>
-->
</section>
<section>
<section>
<h1>BDD in Java</h1>
</section>
<section>
<h2>
<img class="plain" src="img/cucumber.png" />
</h2>
</section>
<section>
<h2>Feature Files (Gherkin)</h2>
findowners.feature
<pre><code class="gherkin" data-trim>
Feature: Finding Owners
Scenario: Owners can be found by last name
Given an owner with last name "Smith"
When searching for "Smith"
Then exactly the given owner is found
</code></pre>
</section>
<section>
<h2>Step Implementation (Java)</h2>
<pre style="font-size:50%"><code data-trim>
public class CustomerStepdefs {
@Given("an owner with last name (.*)")
public void anOwnerWithLastName(String lastName) { ... }
@When("searching for (.*)")
public void searchingFor(String lastName) { ... }
@Then("exactly the given owner is found")
public void exactlyTheGivenOwnerIsFound() { ... }
}
</code></pre>
</section>
<section>
<h2>Problems</h2>
<ul class="fa-ul bad">
<li>Feature files and code must be kept in sync</li>
<li>Programming language features cannot be used in feature files</li>
<li>Limited IDE support (e.g. refactoring)</li>
</ul>
<h3><i class="fa fa-arrow-circle-right"></i> Additional maintenance cost</h3>
</section>
<section>
<h2>Practical Experience</h2>
<ul class="fa-ul bad">
<li>Low acceptance by developers due to additional effort</li>
<li>Non-Developers typically do not write feature files</li>
<li>Developers have to maintain the feature files</li>
</ul>
</section>
<section>
<h2>BDD Frameworks for Java</h2>
<ul>
<li class="nowrap">Cucumber: Plain Text + Java</li>
<li class="nowrap">JBehave: Plain Text + Java</li>
<li>Concordion: HTML + Java</li>
<li>Fitness: Wiki + Java</li>
<li>Spock: Groovy</li>
<li>ScalaTest: Scala</li>
<li>Jnario: Xtend</li>
<li>Serenity (similar concepts as JGiven)</li>
</ul>
</section>
<section data-background="img/wantedposter.jpg" data-background-size="500px">
</section>
<section>
<h2>Stack Overflow?</h2>
</section>
<section class="fade-in">
<div style="position: relative; top:0px;" class="img">
<img width="580px" src="img/stackoverflow.png" />
<div style="z-index: 100; position: absolute; left:220px; top:690px; font-size:10px !important">
<a href="http://stackoverflow.com/questions/16036120/behavior-driven-development-for-java-what-framework-to-use/25221414#25221414">Source: http://stackoverflow.com/questions/16036120/
</a>, <a href="http://stackoverflow.com/users/1371775/sody">
Author: http://stackoverflow.com/users/1371775/sody
</a>
</div>
<div class="fragment">
<img style="background-color: red; padding:10px; position:relative; top: -500px" width="1000px" src="img/stackoverflow-extracted.png" />
<div style="border: red solid 5px; position:relative; top: -305px; left: 180px;width: 600px;height: 50px; opacity:0.3;" />
</div>
</div>
</section>
</section>
<section>
<section>
<img width="600" src="img/logo.svg"/>
</section>
<section>
<h2>Goals</h2>
<ul class="fa-ul goal">
<li>Developer friendly (low maintancence overhead)</li>
<li>Readable tests in in Given-When-Then-Form (BDD)</li>
<li>Reusability of test code</li>
<li>Readable by domain experts</li>
</ul>
</section>
<section>
<h1 style="opacity: 0.8; background: none; border:none; box-shadow:none; -webkit-text-stroke: 2px #555; font-size: 200px; color: white; text-shadow: 5px 5px 15px black">Demo</h1>
</section>
<section>
<h2>Scenarios in JGiven</h2>
<pre><code data-trim>
import org.junit.Test;
import com.tngtech.jgiven.junit.ScenarioTest;
public class FindOwnerTest
extends ScenarioTest<GivenOwner, WhenSearching, ThenOwner> {
@Test
public void owners_can_be_found_by_last_name() {
given().an_owner_with_last_name("Smith");
when().searching_for("Smith");
then().exactly_the_given_owner_is_found();
}
}
</code></pre>
</section>
<section>
<h2>Stage Classes</h2>
<pre><code data-trim>
@JGivenStage // only needed when using Spring
public class WhenSearching extends Stage<WhenSearching> {
@Autowired
ClinicService clinicService;
@ScenarioState
Owner owner;
public WhenSearching searching_for(String name) {
owner = this.clinicService.findOwnerByName(name);
return this;
}
}
</code></pre>
</section>
<section>
<h2>Console Output</h2>
<code><pre>
Owners can be found by last name
Given an owner with last name "Smith"
When searching for "Smith"
Then exactly the given owner is found</pre></code>
</section>
<section>
<h2>HTML5 App</h2>
<a target="_blank" href="examplereport/index.html"><img height="400px" src="img/jgivenhtml5app2.png"/></a>
<ul>
<li><a style="font-size: 30px" href="http://jgiven.org/jgiven-report/html5/">jgiven.org/jgiven-report/html5/</a> <a href="file:///home/jan/git/github/jgiven/jgiven-tests/build/reports/jgiven/html5/index.html" style="font-size:20px">(Local)</a></li>
<li><a style="font-size: 30px" href="https://github.com/mthuret/xke-jgiven/">https://github.com/mthuret/xke-jgiven</a> <a href="file:///home/jans/github/xke-jgiven/target/jgiven-reports/html/index.html" style="font-size:20px">(Local)</a></li>
</ul>
</section>
<section>
<h2>Practical Experience</h2>
<ul style="font-size: 32px">
<li>3 years of experience in a large Java Enterprise project (up to 70 developers)</li>
<li>Over 3000 Scenarios</li>
<li>Readability and reusability of test code has been greatly improved</li>
<li>Maintenance costs of automated tests have been <b>reduced</b> (no hard numbers)</li>
<li>Developers and domain experts work <b>together</b> on the scenarios</li>
<li>Well accepted by developers</li>
<li>Easy to learn by new developers</li>
</ul>
<!--
<li>1. October 2013: First usage in project</li>
<li>30. March 2014: Published as open-source on GitHub</li>
<li>8. September 2014: Article in Java aktuell magazin</li>
<li>10. December 2014: v0.6.0 with new HTML5 Report</li>
<li>10. February 2015: v0.7.0</li>
-->
</ul>
</section>
</section>
<section>
<section>
<h1>Further Features</h1>
</section>
<section>
<h2>Parameter Formatting</h2>
<ul>
<li>Default: toString()
<li class="nowrap">@Format( MyCustomFormatter.class )</li>
<li>@Formatf( " -- %s -- " )
<li>@MyCustomFormatAnnotation
</ul>
</section>
<section>
<h2>Example</h2>
<h3>@OnOff</h3>
<code><pre>@Format( value = BooleanFormatter.class, args = { "on", "off" } )
@Retention( RetentionPolicy.RUNTIME )
@interface OnOff {}</pre></code>
<div class="fragment">
<h4>Apply to parameter</h4>
<code><pre>public SELF the_machine_is_$( @OnOff boolean onOrOff ) { ... }</pre></code>
</div>
<div class="fragment">
<h4>Use step</h4>
<code><pre>given().the_machine_is_$( false );</pre></code>
</div>
<div class="fragment">
<h4>Report</h4>
<code><pre>Given the machine is off</pre></code>
</div>
</section>
<!--
<section>
<h2>Tables as Parameters</h2>
<ul>
<li>Use <a href="http://jgiven.org/javadoc/com/tngtech/jgiven/annotation/Table.html">@Table</a> annotation</li>
<li>Has to be the last parameter</li>
<li>Must be an Iterable of Iterable, an Iterable of POJOs, or a POJO</li>
</ul>
</section>
<section>
<h2>Tables as Parameters</h2>
<h3>Arrays</h3>
<pre><code>SELF the_following_books_are_on_stock( @Table String[][] stockTable ) {
...
}</code></pre>
<ul><li class="nowrap">First row is the table header
</li></ul>
</section>
<section>
<h2>Tables as Parameters</h2>
<h3>Arrays</h3>
<code><pre>@Test
public void ordering_a_book_reduces_the_stock() {
given().the_following_books_on_stock(new String[][]{
{"id", "name", "author", "stock"},
{"1", "The Hitchhiker's Guide to the Galaxy", "Douglas Adams", "5"},
{"2", "Lord of the Rings", "John Tolkien", "3"},
});
when().a_customer_orders_book("1");
then().the_stock_looks_as_follows(new String[][]{
{"id", "name", "author", "stock"},
{"1", "The Hitchhiker's Guide to the Galaxy", "Douglas Adams", "4"},
{"2", "Lord of the Rings", "John Tolkien", "3"},
});
}</pre></code>
</section>
<section>
<h2>Tables as Parameters</h2>
<h3>Console Output</h3>
<code><pre>Scenario: ordering a book reduces the stock
Given the following books on stock
| id | name | author | stock |
+----+--------------------------------------+---------------+-------+
| 1 | The Hitchhiker's Guide to the Galaxy | Douglas Adams | 5 |
| 2 | Lord of the Rings | John Tolkien | 3 |
When a customer orders book 1
Then the stock looks as follows
| id | name | author | stock |
+----+--------------------------------------+---------------+-------+
| 1 | The Hitchhiker's Guide to the Galaxy | Douglas Adams | 4 |
| 2 | Lord of the Rings | John Tolkien | 3 |</pre></code>
</section>
<section>
<h2>Tables as Parameters</h2>
<h3>HTML Report</h3>
<a target="_blank" href="examplereport/index.html#/scenario/com.tngtech.jgiven.example.bookstore.OrderTest/ordering_a_book_reduces_the_stock"><img height="400px" src="img/tablesasparams.png" /></a>
</section>
<section>
<h2>Tables as Parameters</h2>
<h3>List of POJOs</h3>
<ul>
<li class="nowrap">Field name: Header</li>
<li>Feld value: Data</li>
</ul>
<pre><code>SELF the_following_books_are_on_stock( @Table List<BookOnStock> books) {
...
}</code></pre>
</section>
<section>
<h2>Tables as Parameters</h2>
<h3>Simple POJO</h3>
<pre><code>SELF the_following_book(
@Table(includeFields = {"name", "author", "priceInEurCents"},
header = VERTICAL) Book book) {
...
}
</code></pre>
<h4>HTML Report</h4>
<a target="_blank" href="examplereport/index.html#/scenario/com.tngtech.jgiven.example.bookstore.OrderTest/single_POJOs_as_Table"><img src="img/pojoastable.png" /></a>
<!--
<pre><code>
Given the following book
| name | Lord of the Rings |
| author | John Tolkien |
| priceInEurCents | 30 |
</code></pre>
-->
<section>
<h2>@BeforeScenario und @AfterScenario</h2>
<pre><code data-trim>
public class GivenSteps extends Stage<GivenSteps> {
@ProvidedScenarioState
File temporaryFolder;
@BeforeScenario
void setupTemporaryFolder() {
temporaryFolder = ...
}
@AfterScenario
void deleteTemporaryFolder() {
temporaryFolder.delete();
}
}
</code></pre>
</section>
<section>
<h2>@ScenarioRule</h2>
<pre><code data-trim>
public class TemporaryFolderRule {
File temporaryFolder;
public void before() {
temporaryFolder = ...
}
public void after() {
temporaryFolder.delete();
}
}
public class GivenSteps extends Stage<GivenSteps> {
@ScenarioRule
TemporaryFolderRule rule = new TemporaryFolderRule();
}
</code></pre>
</section>
<section>
<h2>@AfterStage, @BeforeStage</h2>
<pre><code class="stretch" data-trim>
public class GivenCustomer extends Stage<GivenSteps> {
CustomerBuilder builder;
@ProvidedScenarioState
Customer customer;
public void a_customer() {
builder = new CustomerBuilder();
}
public void with_age(int age) {
builder.withAge(age);
}
@AfterStage
void buildCustomer() {
customer = builder.build();
}
}
</code></pre>
</section>
<section>
<h2>Tags</h2>
<pre><code>@Test @FeatureEmail
void the_customer_gets_an_email_when_ordering_a_book() {
...
}</code></pre>
<div class="fragment">
<h3>With Values</h3>
<pre><code>@Test @Story( "ABC-123" )
void the_customer_gets_an_email_when_ordering_a_book() { ... }</code></pre>
</div>
</section>
<section>
<h2>@Pending</h2>
<ul>
<li>Marks whole scenarios or single steps as pending</li>
<li>Steps are skipped and marked accordingly</li>
</ul>
<h3>HTML Report</h3>
<a target="_blank" href="examplereport/index.html#/pending"><img src="img/pending.png" /></a>
</section>
<section>
<h2>@Hidden</h2>
<ul>
<li>Marks methods to <b>not</b> appear in the report</li>
<li>Useful for technical methods</li>
</ul>
<pre><code data-trim>
@Hidden
public SELF doSomethingTechnical() { ... }</code></pre>
</section>
<section>
<h2>Extended Step Descriptions</h2>
<pre><code>@ExtendedDescription("The Hitchhiker's Guide to the Galaxy, "
+ "by default the book is not on stock" )
public SELF a_book() { ... }</code></pre>
<h3>HTML Report</h3>
<div style="text-align:center;">
<a target="_blank" href="examplereport/index.html#/scenario/com.tngtech.jgiven.example.bookstore.OrderTest/customers_can_order_books"><img class="plain" src="img/tooltip.png" /></a>
</div>
</section>
<section>
<h2>Attachments</h2>
<pre><code>public class Html5ReportStage {
@ExpectedScenarioState
protected CurrentStep currentStep; // provided by JGiven
protected void takeScreenshot() {
String base64 = ( (TakesScreenshot) webDriver )
.getScreenshotAs( OutputType.BASE64 );
currentStep.addAttachment(
Attachment.fromBase64( base64, MediaType.PNG )
.withTitle( "Screenshot" ) );
}
}</code></pre>
<h3>HTML Report</h3>
<div style="text-align:center;">
<a href="http://jgiven.org/jgiven-report/html5/#/scenario/com.tngtech.jgiven.report.html5.Html5AppTest/attachments_appear_in_the_HTML5_report"><img class="plain" src="img/attachment.png" /></a>
</div>
</section>
</section>
<section>
<section>
<h2>Summary</h2>
<!--
<section style="text-align:center">
<h2>Classical BDD</h2>
<h3>Readable Text <i class="fa fa-arrows-h"></i> Code</h3>
<p style="margin-top:100px"></p>
<h2>JGiven</h2>
<h3>Readable Code <i class="fa fa-long-arrow-right"></i> Readable Report</h3>
</section>
<section>
-->
<ul style="margin-top:0px; font-size:80%;" class="narrow fa-ul check">
<li class="fragment fade-in">Developer friendly</li>
<li class="fragment fade-in">Highly modular and reusable test code</li>
<li class="nowrap fragment fade-in">Just Java, no further language is needed</li>
<li class="fragment fade-in">Easy to integrate into existing test infrastructures</li>
<li class="fragment fade-in">Open Source (Apache 2 Licence)</li>
<li class="fragment fade-in">Maven and Jenkins plugins</li>
<li class="fragment fade-in">Domain experts can <b>read</b> scenario reports</li>
<li class="fragment fade-in not">Domain experts can <b>not write</b> scenarios</li>
</ul>
<p>
<h3 class="fragment fade-in">BDD without the hassle!</h3>
</section>
</section>
<section style="text-align:center" >
<h1>Thank You!</h1>
<h3>@JanSchfr</h3>
<a href="http://jgiven.org"><h3>jgiven.org</h3></a>
<a href="https://github.com/TNG/JGiven"><h3>github.com/TNG/JGiven</h3></a>
<!-- <a href="https://janschaefer.github.io/jugm16-slides/"><h3>janschaefer.github.io/jugm16-slides</h3></a> -->
<p style="margin-top:50px">
<a href="http://tngtech.com"><img style="margin-bottom:20px; margin-top:-10px; height:40px;" src="img/tng.svg" /></a>
</p>
</section>
<section>
<section>
<h1>Backup Slides</h1>
</section>
</section>
<section>
<section>
<h1>Stage Classes</h1>
</section>
<section>
<h2>General</h2>
<ul>
<li>JGiven Scenarios are composed from <b>Stage Classes</b></li>
<li>Stage classes enable <b>modularity</b> and <b>reuse</b></li>
</ul>
</section>
<section>
<h2>State Transfer</h2>
<img width="700" src="img/stages.svg" />
</section>
<section>
<h2>State Transfer</h2>
<ul>
<li>Fields of Stage classes are annotated with <b>@ScenarioState</b> </li>
<li>Values are shared between stages</li>
<li><b>@ProvidedScenarioState</b>, <b>@ExpectedScenarioState</b> are synonyms</li>
</ul>
</section>
<section>
<pre><code data-trim style="min-height:450px">
public class MyGivenStage extends Stage<MyGivenStage> {
@ProvidedScenarioState
int state;
public MyGivenStage some_initial_state() {
state = 42;
return self();
}
}
public class MyWhenStage extends Stage<MyWhenStage> {
@ExpectedScenarioState
int state;
@ProvidedScenarioState
int result;
public MyWhenStage some_action() {
result = state * state;
}
}
</code></pre>
</section>
</section>
<section>
<section>
<h1>Data-Driven Scenarios</h1>
</section>
<section>
<h2>Parameterized Step Methods</h2>
<pre class="fragment fade-in"><code>
given().a_customer_with_name( "John" );
</code></pre>
<div class="fragment fade-in">
<h4>Report</h4>
<pre><code>
Given a customer with name John
</code></pre>
</div>
</section>
<section>
<h2>Within the Sentence?</h2>
<pre><code>
Given there are 5 coffees left
</code></pre>
<h4 class="fragment fade-in">$ to the rescue!</h4>
<pre class="fragment fade-in"><code>
given().there_are_$_coffees_left( 5 );
</code></pre>
</section>
<section>
<h2>Parameterized Scenarios</h2>
<pre><code>@Test
@DataProvider({
"1, 0",
"3, 2",
"5, 4"})
public void the_stock_is_reduced_when_a_book_is_ordered( int initial,
int left ) {
given().a_customer()
.and().a_book()
.with().$_items_on_stock( initial );
when().the_customer_orders_the_book();
then().there_are_$_items_left_on_stock( left );
}</code></pre>
<small>
Uses the DataProviderRunner (<a href="https://github.com/TNG/junit-dataprovider">github.com/TNG/junit-dataprovider</a>).<br> Parameterized Runner and Theories of JUnit are also supported.
</small>
</section>
<section>
<h2>Parameterized Scenarios</h2>
<h3>Console Output</h3>
<code><pre>
The stock is reduced when a book is ordered
Given a customer
And a book
With <initial> items on stock
When the customer orders the book
Then there are <left> items left on stock
Cases:
| # | initial | left | Status |
+---+---------+------+---------+
| 1 | 1 | 0 | Success |
| 2 | 3 | 2 | Success |
| 3 | 5 | 4 | Success |</pre></code>
</section>
<section>
<h2>Parameterized Scenarios</h2>
<h3>HTML Report</h3>
<a target="_blank" href="examplereport/index.html#/scenario/com.tngtech.jgiven.example.bookstore.OrderTest/the_stock_is_reduced_when_a_book_is_ordered"><img src="img/datatable.png" /></a>
</section>
<section>
<h2>Derived Parameters</h2>
<pre><code>@Test
@DataProvider({"1", "3", "5"})
public void the_stock_is_reduced_when_a_book_is_ordered( int initial ) {
given().a_customer()
.and().a_book()
.with().$_items_on_stock( initial );
when().the_customer_orders_the_book();
then().there_are_$_items_left_on_stock( initial - 1 );
}</code></pre>
</section>
<section>
<h2>Derived Parameters</h2>
<h3>Console Output</h3>
<code><pre>
The stock is reduced when a book is ordered
Given a customer
And a book
With <initial> items on stock
When the customer orders the book
Then there are <numberOfItems> items left on stock
Cases:
| # | initial | numberOfItems | Status |
+---+---------+---------------+---------+
| 1 | 1 | 0 | Success |
| 2 | 3 | 2 | Success |
| 3 | 5 | 4 | Success |</pre></code>
</section>
<section>
<h2>Derived Parameter</h2>
<h3>HTML Report</h3>
<a target="_blank" href="examplereport/index.html#/scenario/com.tngtech.jgiven.example.bookstore.OrderTest/the_stock_is_reduced_when_a_book_is_ordered_2"><img src="img/derivedparams.png" /></a>
</section>
<section>
<h2>Different Steps</h2>
<pre><code>@Test
@DataProvider({ "3, 2, true",
"0, 0, false" })
public void the_stock_is_only_reduced_when_possible(
int initial, int left, boolean orderExists) {
given().a_customer()
.and().a_book()
.with().$_items_on_stock( initial );
when().the_customer_orders_the_book();
if ( orderExists ) {
then().a_corresponding_order_exists_for_the_customer();
} else {
then().no_corresponding_order_exists_for_the_customer();
}
}</code></pre>
</section>
<section>
<h2>Different Steps</h2>
<h3>Console Output</h3>
<code><pre> The stock is only reduced when possible
Case 1: initial = 3, left = 2, orderExists = true
Given a customer
And a book
With 3 items on stock
When the customer orders the book
Then there are 2 items left on stock
And a corresponding order exists for the customer
Case 2: initial = 0, left = 0, orderExists = false
Given a customer
And a book
With 0 items on stock
When the customer orders the book
Then there are 0 items left on stock
And no corresponding order exists for the customer</pre></code>
</section>
<section>
<h2>Different Steps</h2>
<h3>HTML Report</h3>
<a target="_blank" href="examplereport/index.html#/scenario/com.tngtech.jgiven.example.bookstore.OrderTest/the_stock_is_only_reduced_when_possible"><img height="400px" src="img/differentsteps.png"/></a>
</section>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
showNotes: false,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); },
callback: function() {
hljs.configure({ languages: ['java'] });
hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>