Upgrade to Pro — share decks privately, control downloads, hide ads and more …

QA&Test Bilbao - API Testing for embedded proje...

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

QA&Test Bilbao - API Testing for embedded projects with Testcontainers and Wiremock

Embedded software engineers can have nice things, too! Overview of Testcontainers and WireMock usage for C/C++ projects

Avatar for Oleg Nenashev

Oleg Nenashev PRO

October 24, 2023
Tweet

More Decks by Oleg Nenashev

Other Decks in Technology

Transcript

  1. Fake it until you `make it` API Integration testing of

    embedded projects with Testcontainers and WireMock Oleg Nenashev, WireMock Inc QA&Test 2023 Bilbao
  2. Integration testing? 3 • Multiple technology stacks and toolchains •

    Many teams involved • Sacred knowledge • [Almost] always too late
  3. Outline • Intro to API integration testing • Testcontainers and

    WireMock • Using them together • And examples! C/C++, Golang, Rust 4 bit.ly/qatest2023_wiremock Disclaimer: This is a talk about “WireMock AND Testcontainers”, not “VERSUS” ir “OR”. Your mileage may vary These slides:
  4. > whoami @oleg_nenashev oleg-nenashev Dr. Nenashev / Mr. Jenkins Developer

    tools hacker Community builder & DevRel consultant #RussiansAgainstPutin #StandWithUkraine
  5. Docker • Popular container engine • Developer-friendly • Huge ecosystem

    • DockerHub and Container Registries • Docker Compose – multi-container apps • Universal image format (OCI) https://www.docker.com/
  6. APIs are essential for Integration Testing 14 GROWTH IN WEB

    APIS SINCE 2005 Over 90% of developers use APIs. Skyrocket growth of APIs JANUARY 2006 JANUARY 2008 JANUARY 2010 JANUARY 2012 JANUARY 2014 JANUARY 2016 JANUARY 2018 MONTH The growth over time of the Programmable Web API API directory to more than 22,000 entries 22000 20000 18000 16000 14000 12000 10000 8000 6000 4000 2000 0 TOTAL API COUNT Programmable Web * Gartner Hype Cycle for APIs, 2022
  7. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Mocking at the API provider level (e.g. WireMock) 4. Mocking at the code level 18 Slow Fast Accu- rate Nope
  8. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Mocking at the API provider level (e.g. WireMock) 4. Mocking at the code level 19 Slow Fast Nope Accu- rate
  9. 21 Build Unit tests Publish Reports Integration tests Publish Reports

    NOW “Shift Left” Fast integrations tests are critical
  10. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Mocking at the API provider level (e.g. WireMock) 4. Mocking at the code level 24 Slow Fast Accu- rate Nope
  11. 25

  12. 27

  13. Containers are not always slow! • On-demand image build •

    Caching Docker image builds • Suspending containers between tests • Graceful termination ◦ github.com/testcontainers/moby-ryuk 29 testcontainers.org
  14. Ways to do API integration testing 1. Testing against Production/Staging

    servers 2. Testing against a simplified/containerized instance (e.g. Testcontainers) 3. Mocking at the API provider level (e.g. WireMock) 4. Mocking at the code level 31 Slow Fast Accu- rate Nope
  15. 32 WireMock 101 WireMock is a tool for building mock

    APIs Created in 2011 as a Java test library and CLI Available beyond Java, inc Rust or Golang You can can: • Create stable development environments • Isolate yourself from flakey 3rd parties • Simulate APIs that don't exist yet wiremock.org
  16. 33 wiremock.org/docs/stubbing IF (request_url) THEN (response) * * it gets

    MUCH more complex WireMock Config JSON: Client library response request Client App Mock API Server HTTP/2
  17. Comparison [1/2] 1. Testing against Production/Staging servers 2. Testing against

    a simplified/containerized instance (e.g. Testcontainers) 3. Mocking at the API provider level (e.g. WireMock) 4. Mocking at the code level 39 Slow Fast Nope Accu- rate
  18. 40

  19. WireMock as a Proxy 43 Tests Real API Provider OR

    • Fault injection • Recording • Protocol Verification
  20. Testcontainers for C/C++ 48 Started by the WireMock Team in

    September 2023 We have Embedded/Automotive customers and users who need it Based on Testcontainers or Go WireMock module github.com/testcontainers/testcontainers-c
  21. Example - WireMock with C code 49 github.com/testcontainers/testcontain ers-c/tree/main/examples/wiremock •

    Testcontainers C is an experimental project • Feedback is welcome! • See more examples in the repository: CppUnit, OpenSCADA, etc.
  22. Takeaways 53 • Shift left your integration testing • Mocking

    APIs and services, reducing external dependencies, containers • There are tools for that, including WireMock and Testcontainers • WireMock and Testcontainers co-exist well • They work for embedded use-cases!
  23. Choosing a right tool * ** * Your mileage may

    vary ** You will often need both and that’s OK! Need database or complex dynamic environment? Yes Server implementation is ready? Is it containerized and lightweight? Can you [easily] transfer the system to the required state in test? No No No No Yes Yes Yes 54
  24. WireMock Cloud by WireMock Inc. 57 • Small startup •

    WireMock creator is a co-founder of the Inc. • WireMock Cloud - SaaS for end-to-end API mocking • Private beta: K8s Edition for managed / on-premises wiremock.io
  25. Credits to • All WireMock contributors • WireMock Inc. Team

    • All Testcontainers contributors and AtomicJar folks • All FOSS contributors 58