Slide 1

Slide 1 text

TDD It’s easier than you think! Eric Deandrea Sr. Principal Developer Advocate @ Red Hat @edeandrea

Slide 2

Slide 2 text

Who am I? ● 25+ years software development experience ○ ~11 years as DevOps Architect in financial services / insurance Java Champion ● Contributor to Open Source Projects Quarkus Spring Boot, Spring Framework, Spring Security LangChain4j (& Quarkus LangChain4j) Wiremock Microcks ● Build & deliver cloud-native development training programs ● Published author ● Avid boater & black belt in martial arts @edeandrea

Slide 3

Slide 3 text

https://red.ht/quarkus-spring-devs ● Showcase & explain Quarkus, how it enables modern Java development & the Kubernetes- native experience ● Introduce familiar Spring concepts, constructs, & conventions and how they map to Quarkus ● Equivalent code examples between Quarkus and Spring as well as emphasis on testing patterns & practices 3

Slide 4

Slide 4 text

Why are we here today?

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

6

Slide 7

Slide 7 text

6

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

11

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

https://x.com/holly_cummins/status/1788138252572004441

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

But first, Some basics

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

end-to-end tests high realism high value

Slide 21

Slide 21 text

end-to-end tests unit tests low effort high realism high value

Slide 22

Slide 22 text

end-to-end tests unit tests integration tests low effort high realism high value

Slide 23

Slide 23 text

end-to-end tests unit tests integration tests low effort high realism

Slide 24

Slide 24 text

end-to-end tests unit tests integration tests low effort high realism tests with application server test REST endpoints tests with a database

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Unit testing

Slide 27

Slide 27 text

Unit testing ● Isolate a “unit” within the application as a standalone entity

Slide 28

Slide 28 text

Unit testing ● Isolate a “unit” within the application as a standalone entity ● Use mocking / spying to control dependencies of the unit during test

Slide 29

Slide 29 text

Unit testing ● Isolate a “unit” within the application as a standalone entity ● Use mocking / spying to control dependencies of the unit during test ● Test all potential outcomes of a particular unit

Slide 30

Slide 30 text

Unit testing ● Isolate a “unit” within the application as a standalone entity ● Use mocking / spying to control dependencies of the unit during test ● Test all potential outcomes of a particular unit ● Should be run on all builds & before code is merged

Slide 31

Slide 31 text

Mocking

Slide 32

Slide 32 text

Mocking ● Complete mock / “fake” object

Slide 33

Slide 33 text

Mocking ● Complete mock / “fake” object ● User must define interaction(s)

Slide 34

Slide 34 text

Mocking ● Complete mock / “fake” object ● User must define interaction(s) ● Default behavior if not defined: do nothing

Slide 35

Slide 35 text

Mocking ● Complete mock / “fake” object ● User must define interaction(s) ● Default behavior if not defined: do nothing ● Can verify intended behaviors occurred after test (verification-based testing)

Slide 36

Slide 36 text

Spying

Slide 37

Slide 37 text

Spying ● Partial mock / “real” object

Slide 38

Slide 38 text

Spying ● Partial mock / “real” object ● User doesn’t need to define interaction(s)

Slide 39

Slide 39 text

Spying ● Partial mock / “real” object ● User doesn’t need to define interaction(s) ● Default behavior if not overridden: perform actual operation on object

Slide 40

Slide 40 text

Spying ● Partial mock / “real” object ● User doesn’t need to define interaction(s) ● Default behavior if not overridden: perform actual operation on object ● Useful for “watching” objects during tests & verifying intended behaviors occurred (verification-based testing)

Slide 41

Slide 41 text

Integration testing

Slide 42

Slide 42 text

Integration testing ● Treat application as a black box

Slide 43

Slide 43 text

Integration testing ● Treat application as a black box ● Downstream services (db, message brokers, etc) need to be available

Slide 44

Slide 44 text

Integration testing ● Treat application as a black box ● Downstream services (db, message brokers, etc) need to be available ● Application should be run & tested as its intended to be deployed

Slide 45

Slide 45 text

Integration testing ● Treat application as a black box ● Downstream services (db, message brokers, etc) need to be available ● Application should be run & tested as its intended to be deployed ● Should be run before code is merged

Slide 46

Slide 46 text

Today’s challenge

Slide 47

Slide 47 text

229449 HTTP (REST) adoptions topic adoption-requests topic Get / Persist pet info

Slide 48

Slide 48 text

https://bit.ly/tdd-easy

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Additional resources

Slide 51

Slide 51 text

Kubernetes Native Java with Quarkus https://www.infoq.com/articles/native-java-quarkus Deployment Developer Joy ● Quickly & easily build Kubernetes-Native Java applications ● Industry leader in startup time and memory utilization for native and JVM applications ● One step native executable generation ● Leverage existing Java, Jakarta, MicroProfile, & Spring expertise ● Imperative & reactive APIs side-by-side ● Live coding with zero config

Slide 52

Slide 52 text

https://www.oreilly.com/library/view/reactive-systems-in/9781492091714 https://developers.redhat.com/e-books/understanding-quarkus https://developers.redhat.com/e-books/practising-quarkus

Slide 53

Slide 53 text

https://quarkus.io/blog/quarkus-superheroes-to-the-rescue https://github.com/quarkusio/quarkus-super-heroes Quarkus Superheroes

Slide 54

Slide 54 text

https://quarkus.io @quarkusio https://quarkus.io/community

Slide 55

Slide 55 text

Thank you!