Integration Tests with Super Powers And even more... Alexandre - - PowerPoint PPT Presentation

integration tests with super powers
SMART_READER_LITE
LIVE PREVIEW

Integration Tests with Super Powers And even more... Alexandre - - PowerPoint PPT Presentation

Integration Tests with Super Powers And even more... Alexandre Figura Site Reliability Engineer @ SysEleven GmbH A Brillant Masterpiece Irresistibly Entertaining The Python Magazine Edinburgh Times


slide-1
SLIDE 1

Integration Tests
 with Super Powers

And even more...

Alexandre Figura · Site Reliability Engineer @ SysEleven GmbH

slide-2
SLIDE 2

A Brillant Masterpiece Golden Snake Awards

Nominated for

Best Speaker

Alexandre Figura

⭐⭐⭐⭐⭐ The Most Exciting Talk of the Year ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐

The Python Magazine Scottish Insiders

Irresistibly Entertaining ⭐⭐⭐⭐⭐

Edinburgh Times

slide-3
SLIDE 3

Who Am I?

3

  • Use Python with 😎 since 2014.
  •  Live in Berlin 🛬 since 2016 
  • Always eat 2 desserts at lunch 🍧
  • Work with cool folks at SysEleven GmbH,


best company in town.

slide-4
SLIDE 4

Tests and
 Programmers

❤ A True Love Story ❤

slide-5
SLIDE 5

5

A Well-Kept Secret

There is one And only one Reason why we write tests. We want our Pull-Requests to get accepted. And incidentally, to make it easier to maintain our code in the future.

slide-6
SLIDE 6

Lazy Mocking

Or how harmful mocks can be...

slide-7
SLIDE 7

7

Mocks

Advantages

  • Easy to write.

Drawbacks

  • Dependant on implementation,
  • Make refactoring harder,
  • Hide errors and behavioral changes.

Conclusion Never use them*

*Unless you have a very good reason...

slide-8
SLIDE 8

Please Do Not Try Mocks at Home

slide-9
SLIDE 9

Alternative Testing Strategies

...Pimp my Mock™...

slide-10
SLIDE 10

10

Basic Concepts

Integration Tests are built around two ideas:

  • 1. Dependency Injection,
  • 2. Interface Testing.

It sounds complicated. But it isn't.

slide-11
SLIDE 11

11

Summary

Advantages:

  • Tests not dependant anymore on implementation.
  • Easy to change dependency later on.
  • Make refactoring easier.

Drawbacks:

  • Require way more work at first.
slide-12
SLIDE 12

Real World Example

When practice meets theory...

slide-13
SLIDE 13

13

To the Cloud and Beyond

Use Case We want to upload a static website To the Cloud Using OpenStack Object Store's API. Links:

  • Officiel API, - Fake Implementation,
  • Interface Tests,
  • Parametrizing with Pytest.

Container Object Object Object Object Object Store

slide-14
SLIDE 14

Additional Examples


  • f

Dependency Injection

Let's eat the snake!

slide-15
SLIDE 15

15

Mock Injection

Too much work to write Fake dependencies?

  • Write a Mock-like implementation,
  • Inject it as a dependency.

Useful for simulating complex systems. Advantages:

  • Easy as mocks,
  • Tests remaining independent of implementation


(makes refactoring easier).

slide-16
SLIDE 16

16

Minimalist Interface Testing

Use Case: I make Holiday movies Recorded on Blu-ray And need to convert them to MKV. Problem: A Blu-Ray is 30-50GB large. Solution: Only check for syntax errors. Links:

  • Syntax Errors Testing,
  • Fake Implementations,
  • Dependency Injection.
slide-17
SLIDE 17

💹 Bonus 💹 Running inside Docker Compose

Because Buzzwords matter...

slide-18
SLIDE 18

18

Standard Workflow

Tests independent

  • f running platform.

Working example available on Github. Docker Compose Application Container Container 2 Container 3 Source Code Tox +
 Pytest Container 4

slide-19
SLIDE 19

Conclusion

What you should remember

slide-20
SLIDE 20

20

Summary

Mocks make refactoring harder. Interface Testing is more flexible, but involves more work. Dependency Injection will improve your code's API. Always ask yourself (or around)
 if you need 100% test coverage.

slide-21
SLIDE 21

Everything is about Tradeoffs

slide-22
SLIDE 22

We're hiring! Interested? 
 Just say: "Hello!"

Mail: jobs@syseleven.de WhatsApp, SMS: +49 171/8934073