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

WTM21 - Unit Tests 101 by Ana Carolina Riekstin...

WTM21 - Unit Tests 101 by Ana Carolina Riekstin and Myriam Moar

What are unit tests, what is the purpose of writing, the benefits (and costs), how to write them? If you are looking for a place to start your unit tests journey, or build the courage to finally attack that refactoring you have been postponing, look no further!

Ana Carolina Riekstin
Montreal, Qc, Canada / Bell
Software Developer
Ana Carolina is a Brazilian based in Montreal who has been around research and development related to computer networks and network management, smart homes and cities, and sustainability. Currently a Software Developer at Bell, holds a PhD in computer engineering. Loves to talk, specially about her dog, Caco, and Brazilian cheese bread recipes. Still searching for the answer to life, the universe and everything.

Myriam Moar
Lévis, Québec / Elapse Technologies
Software Developer at Elapse Technologies
Myriam Moar works as a software developer and resident in the mentoring and improvement program at Elapse Technologies. This program aims to train future teachers and coaches in the field of software engineering. Motivated by learning new knowledge, whether technical or human, Myriam is always pushing her involvement in the field. Committed to continuous improvement, she is particularly involved as a teaching assistant at Université Laval, where she addresses quality and tests, but also the challenges of team collaboration in software engineering. After all, people are at the center of all collaborative work. Her everyday approach tends to focus on the importance and contribution of individuals within a team.

Women Techmakers Montreal

March 19, 2021
Tweet

More Decks by Women Techmakers Montreal

Other Decks in Programming

Transcript

  1. Why? ↑ good practices, doc, refactoring... 02 How to Test

    conventions, mocks, helpers, setups TABLE OF CONTENTS What? What is a unit, classification 01 What to Test Contracts and behaviors 04 03 Conclusion TDD, BDD, other languages, refs Demo Time python > pytest, fixtures, mocks 06 05
  2. TEST PYRAMID MARS SMALL 70% More isolation More integration MEDIUM

    20% LARGE 10% e2E Tests Slower $$$ Faster $ Integration Tests UNIT Tests
  3. Other shapes MARS More isolation More integration e2E Tests Slower

    Faster Integration Tests UNIT Tests The Ice Cream Cone The Hourglass
  4. Guides Development Critiques the product Business Technology Unit Test Functional

    Tests Load Testing UAT (User Acceptance Testing) Performance Testing Security Testing Scenarios Exploratory Testing Component Tests UX Testing Simulations Q2 Q3 Q1 Q4 Testing quadrant
  5. The Process is more than just “tests” CLEANER CODE Hints

    on how to improve the code ... BETTER ARCHITECTURE … and the architecture EXPLORATION Explore your codebase → learn Documentation Good tests will tell you a story > reqs. FAST RETROACTION Very quick feedback; sooner → cheaper Refactoring Reduces the risks
  6. GIVEN-WHEN-THEN Use a naming convention to easily identify your test

    case Conventions AND TIPS refactoring Unit tests are part of the code, they deserve it too Test only one thing Your test should have only one reason to fail USE MEANINGFUL NAMES Your test should read like a story
  7. Demo with Pytest PYTEST • parametrize • raises Assertions •

    assert • grappa > should Mocking • unittest.mock > Mock > return_value • patch > side_effect • monkeypatch
  8. Some References Unit tests • Working effectively with legacy code,

    a book by Michael C. Feathers • https://martinfowler.com/bliki/UnitTest.html • Test or not to test, that is the question: https://medium.com/@tasdikrahman/what-should-and-s hould-not-be-tested-in-unit-tests-7e6bdeb744e4 • You Still Don’t Know How to Do Unit Testing (and Your Secret is Safe with Me): https://stackify.com/unit-testing-basics-best-practices/ TDD • https://devqa.io/pros-cons-test-driven-development/ JAVA • https://www.toptal.com/java/unit-integration-junit-tests Growing Object-Oriented Software, a book by Steve Freeman and Nat Pryce C# • https://stackify.com/unit-testing-basics-best-practices/ Python • https://www.oreilly.com/library/view/python-testing-with /9781680502848/ Python Test With pytest, a book by Brian Okken • Pytest: https://docs.pytest.org/en/stable/contents.html • More: https://realpython.com/python-testing, • Unittest: https://docs.python.org/3/library/unittest.html • Mocking: https://www.toptal.com/python/an-introduction-to-mock ing-in-python • Mocking, Monkey Patching... https://codefellows.github.io/sea-python-401d7/lectures/ mock.html • Mock, another "tool": https://medium.com/ryans-dev-notes/python-mock-and -magicmock-b3295c2cc7eb Go • https://golang.org/pkg/testing • https://medium.com/rungo/unit-testing-made-easy-in-g o-25077669318
  9. CREDITS: This presentation template was created by Slidesgo, including icons

    by Flaticon, infographics & images by Freepik THANKS! Do you have any questions? [email protected] [email protected]