Be or not to be
in a pyramid of testing

Juan Antonio Breña Moral

The "To be or not to be" soliloquy appears in Act 3, Scene 1 of Shakespeare's Hamlet.
In this scene, often called the "nunnery scene," Prince Hamlet thinks about life, death, and suicide.
Specifically, he wonders whether it might be preferable to commit suicide to end one's suffering and to leave behind the pain and agony associated with living.

How to live an agony with the lack of testing?
This is the question...

Who I am

Juan Antonio Breña Moral
Technical Product Owner for Shared Platform @ Atradius CIO
Twitter | Github | Linkedin
Quotes: “Lead me, follow me, or get out of my way.”
"Pressure makes diamonds."

- George S. Patton Jr.
"Quality is never an accident; it is always the result of intelligent effort."
- John Ruskin
“Program testing can be used to show the presence of bugs, but never to show their absence!”
- Edsger W. Dijkstra
“Discovering the unexpected is more important than confirming the known.”
- George E. P. Box
"Quality is not an act, it is a habit."
- Aristotle
“If you're not failing, you're not trying hard enough.”
- Martin Fowler
Source: Leavitt's Alignment Model (1965) >> People, Process and Technology Framework

Agenda

  • Who I am
  • Testing in the SLDC
  • Types of software testing
  • Shapes of pyramids of testing
  • Testing libraries
  • Takeaways
  • References
  • Q&A

Testing in the SLDC

Source: https://datarob.com/essentials-software-development-life-cycle/

Testing in the SLDC

Questions for the audience:

What is the percentage of your time invested in testing in a Sprint?

Testing in the SLDC

Approximately 40-50% of the total software development project lifecycle cost involves testing, which is in line with industry software cost models.

Tim Crumbley (NASA)

Note: IMHO, the % should be higher in Distributed systems. (70%-80%)

Testing in the SLDC

V-Model

Source: https://www.geeksforgeeks.org/software-engineering-sdlc-v-model/

The Cost of Finding Bugs Later in the SDLC

Source: https://www.functionize.com/blog/the-cost-of-finding-bugs-later-in-the-sdlc

C4 Model

C4 Model

C4 Model

C4 Model

Types of software testing

Unit testing

Source: https://martinfowler.com/bliki/UnitTest.html

Unit testing

Unit testing is a type of software testing where individual units or components of a software are tested. The purpose of unit testing is to validate that each unit of the software performs as expected.

Concepts

  • Mocks: Mocking is the practice of creating simulated versions of the objects in the code, and then using these mock objects to mimic the behavior of the real objects or services so that we can test parts of the code in isolation.
  • Stubs: A stub is a test double that returns a configured response every time when an expected interaction happens between the system under test and a stub.
Interesting article: Mocks Aren't Stubs

Concepts



< plugin>
	< artifactId>maven-surefire-plugin< /artifactId>
	< version>3.5.2< /version>
	< configuration>
		< includes>
			< include>**/*Test.java< /include>
		< /includes>
	< /configuration>
< /plugin>

						

Integration testing

Questions for the audience:

When is better not not use Mocks and it is better to create an Integration test?

Integration testing

Integration tests test the plumbing and choreography of the components.
- Uncle Bob Martin

Integration testing

Source: https://katalon.com/resources-center/blog/integration-testing

Integration testing

Integration testing is a type of software testing where the software is tested as a whole, to ensure that the different parts of the software work together as expected.

Integration testing

Source: https://www.structurizr.com/share/1/diagrams#Components

Integration testing

Every service has an integeration testing solution:

Service Solution
HTTP WireMock
Database (Provider X) TestContainers
Messaging Broker TestContainers
Cache TestContainers
Further information: https://www.testcontainers.org/

Integration testing

Source: https://developers.redhat.com/e-books/quarkus-action

Integration testing

  • Testing with a Mock Environment: @SpringBootTest
  • Testing with a Running Server: @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
Source: https://docs.spring.io/spring-boot/reference/testing/spring-boot-applications.html#testing.spring-boot-applications.with-running-server

Concepts



< plugin>
	< groupId>org.apache.maven.plugins< /groupId>
	< artifactId>maven-failsafe-plugin< /artifactId>
	< version>3.5.2< /version>
	< configuration>
		< argLine>${argLine} --enable-preview< /argLine>
		< includes>
			< include>**/*IT.java< /include>
		< /includes>
	< /configuration>
< /plugin>

						

Other tests

  • Mutation testing
  • Chaos/Toxi/Resilience tests
  • Performance tests
  • Architecture tests
  • Security tests
  • Property-based testing (PBT)
  • ...

Shapes of pyramids of testing

Classical testing pyramid:

Source: https://engineering.atspotify.com/2018/01/testing-of-microservices/

Shapes of pyramids of testing

What is the nature of your software?

  • Microservices
  • Monolithic
  • Mobile
  • Web
  • Libraries

Shapes of pyramids of testing

If you think in a Microservice architecture...

Shapes of pyramids of testing

Spotify testing model for Microservices:

Source: https://engineering.atspotify.com/2018/01/testing-of-microservices/

Shapes of pyramids of testing

From:

Source: https://engineering.atspotify.com/2018/01/testing-of-microservices/

Shapes of pyramids of testing

To:

Source: https://engineering.atspotify.com/2018/01/testing-of-microservices/

Shapes of pyramids of testing

  • Unit Testing: Test 1 thing, alone
  • Integration Testing: Test a few things, together
  • End-to-end (E2E) Testing: Test that everything works together (run the app)

Testing libraries

  • mockito
  • assertj
  • junit-jupiter-params
  • jqwik
  • pitest
  • wiremock
  • testcontainers
  • toxiproxy
  • jmeter-java-dsl
  • archunit

Takeaways

  • Everything begin with a good specification
  • Testers/QA is not an isolated role
  • Every team member has to test
  • Measure that you invest more time in testing than development
  • If you don't have a Love/Hate feeling with your tests, your are not testing hard enough

Takeaways

  • Psycological safety is fundamental for a healthy testing culture
  • Reward a bug hunting culture
  • Punish a culture where bug / design flaws are hidden
  • Add testing as part of Definition of Done (DoD)
  • Test automation is not a silver bullet

Takeaways

  • Reduce the number of dependencies in general
  • Don't develop tests only for passing the Sonar Gate
  • Verify the quality of your tests with Mutation testing
  • Testcontainers is not an optional technique
  • Testing is a skill, and like any other skill, it can be learned
  • Invest time test naming
  • Use Given/When/Then in your tests

Takeaways

  • Trust in your development executed in the pipeline, not in your local development
  • Don't code tests only for happy path
  • Tests are another kind of documentation
  • Zero trust

References

Mockito made clear

Source: https://pragprog.com/titles/mockito/mockito-made-clear/

Mockito Cookbook

Source: https://www.amazon.com/-/es/Marcin-Grzejszczak-ebook/dp/B00LA414IM

Instant Mockito

Source: https://www.amazon.com/Instant-Mockito-Marcin-Grzejszczak/dp/1782167978

Unit Testing in Java with JUnit

Source: https://pragprog.com/titles/utj3/pragmatic-unit-testing-in-java-with-junit-third-edition/

Unit Testing

Source: https://pragprog.com/titles/utj2/pragmatic-unit-testing-in-java-8-with-junit/

Fifty quick ideas to improve your tests

Source: https://fiftyquickideas.com/fifty-quick-ideas-to-improve-your-tests/

Test Driven Development: By Example

Source: https://www.amazon.com/Test-Driven-Development-Kent-Beck/dp/0321146530

Extreme Programming Explained


Source: https://kentbeck.com/

Specification by Example


Source: https://gojko.net/books/specification-by-example/

RESTest: Automated Black-Box Testing of RESTful Web APIs


Source: RESTest: Automated Black-Box Testing of RESTful Web APIs

🙏 🙏 🙏

Thanks