SlideShare une entreprise Scribd logo
1  sur  105
Télécharger pour lire hors ligne
VictorRentea.ro
The Art of Unit Testing
The Circle of Purity
VictorRentea.ro
Independent Trainer
Lead Architect at IBM
When something is painful
but you can't avoid doing it…
postpone it
When something is painful
but you can't avoid doing it…
delegate it
When something is painful
but you can't avoid doing it…
Do It More Often!
"Bring The Pain Forward!"
Continuous Integration
Pair Programming
Continuous Refactoring
TDD
XP
"Bring The Pain Forward!"
Victor Rentea
14 years of Java
Clean Code Evangelist
VictorRentea.ro
30+ talks, 12 meetups
.NET
Lead Architect
Tech Team Lead and Consultant
Software Craftsman
XP: Pair Programming, Refactoring, TDD
VictorRentea.ro @victorrentea victor.rentea@gmail.com
Independent
Technical Trainer & Coach
HibernateSpring Java 8
Architecture, DDDDesign Patterns
Clean Code Unit Testing, TDD
Java Performance and much more…Scala
180+ days1300 devs6 years
VictorRentea.rovictor.rentea@gmail.com
30 companies
Posting daily on
VictorRentea.ro
▪Test Design Principles
▪TDD
▪Mocks
▪Databases
▪Legacy Code
Agenda
15
VictorRentea.ro
▪Arrange: setup the test fixture
▪Act: call the production code
▪Assert the outcomes
▪Annihilate[opt]: clean up
Terms
16 Professional Unit Testing – Basics
VictorRentea.ro
Why do we
Write Tests ?
17
VictorRentea.ro
Full: https://www.youtube.com/watch?v=GvAzrC6-spQ
Why do we Write Tests ?
18 Professional Unit Testing – Basics
Uncle Bob on TDD
Shorter: https://youtu.be/GvAzrC6-spQ?t=116
1:48
VictorRentea.ro19 Professional Unit Testing – Intro
To Read-the-Spec™
(before we finish the implem☺)
Why do we Write Tests ?
FEAR
VictorRentea.ro
Medical Screening
20 Professional Unit Testing – Principles of Test Design
VictorRentea.ro
Sensitive
Specific
Fast
Few
Clinical Tests
21 Professional Unit Testing – Principles of Test Design
VictorRentea.ro
Sensitive
High Coverage %
Correct Tests
Specific
Expressive
Isolated & Robust
Low overlap
Fast
Few
Small, DRY tests
Test Design Goals
22 Professional Unit Testing – Principles of Test Design
= Maintainable
fail for any bug
precise failures
VictorRentea.ro
Test code >> Prod code
Not maintainable?
Under pressure, devs might:
23 Professional Unit Testing – Principles of Test Design
@Ignore
delete test
delete asserts
// comment test
invert asserts
// @Test
VictorRentea.ro24
VictorRentea.ro
▪Code that you fear 😱
(hard to understand)
▪A distant corner in the logic
(takes 3 mins of UI clicks to reproduce)
▪A bug (before fixing it) 🏆
▪for/if/while ⚙
▪Thrown exception
▪A method that just calls two others
▪Trivial code
▪Legacy code with 0 bugs, 0 changes
(over the last year)
Testing Priorities
25 Professional Unit Testing – Basics
PRIORITY
a.setName(b.getName());
*in case you're not 100% TDD
VictorRentea.ro
Tests are green.
You implement a huge CR in Prod code.
Tests are green.
Evergreen Tests
26
We ❤ Green Tests!
VictorRentea.ro
Evergreen Tests
27
VictorRentea.ro
Evergreen Tests
28
Coverage% = ?
VictorRentea.ro
Can you
TrustSuch Tests?
29
VictorRentea.ro30
How can you check
that your test really
covers what it says?
VictorRentea.ro33 Professional Unit Testing – Test Design Guidelines
Mutation Testing
You make some change
to the Production code
You get some "mutant" code The tests should squash
the mutant by turning red
You run the Tests You undo the change
There are frameworks that play like this with your code,
but their results might be depressing
Tests fail ֞ Production code is altered
How can you check
that your test really
covers what it says?
VictorRentea.ro
Always see your test failing
at least once
34
Tests, like laws, are meant to be broken
VictorRentea.ro
▪Regression
- Yeehaaa! ➔ fix it
▪Change Request
- Double Check ➔ Update/Delete it ?
▪Iso-functional changes
- Superficial API Changes ➔ adjust the test
- Refactoring internals ➔ loosen the test coupling
▪A Bug in a Test
- Usually discovered via debugging ➔ fix the test
Why can a Test Fail ?
35 Professional Unit Testing – Test Design Guidelines
the usual suspect = production code
VictorRentea.ro
A Bug in a Test
36 Professional Unit Testing – Test Design Guidelines
VictorRentea.ro37 Professional Unit Testing – Test Design Guidelines
A Bug in a Test
VictorRentea.ro38 Professional Unit Testing – Test Design Guidelines
VictorRentea.ro39 Professional Unit Testing – Test Design Guidelines
VictorRentea.ro
Concatenation, arithmetic
40 Professional Unit Testing – Test Design Guidelines
assertEquals("Greetings" + name, logic.getGreetings(name));
if, switch
Did you also tested that logic? ("test the tests" ☺)
it's missing a " "!
Why? The same Dev wrote both prod and test code! ☺ CPP
➔ Prefer literals 
assertEquals("Greetings John", logic.getGreetings("John"));
Can you find the bug?
VictorRentea.ro
catch-assert
When you want to verify an exception is thrown
41 Professional Unit Testing – Test Design Guidelines
try {
logicThatShouldThrow();
fail("should have thrown");
} catch (MyException ex) {
assert("msg", ex.getMessage());
}
Can you find the bug?
VictorRentea.ro
Verify an Exception Type is Thrown
42 Professional Unit Testing – Test Design Guidelines
@Rule
public ExpectedException exception = none();
@Test
public void expectExceptionWithDetails() {
exception.expectMessage("contains this"); // or…
exception.expect(exceptionWithCode(FILE_LOCKED));
// throwing code
}
@Test(expected = IllegalArgumentException.class)
public void expectExceptionTypeThrown() {
// throwing code
}
Verify Exception Message/Code
For precision: let's create 20 new Exception classes !
Hamcrest
VictorRentea.ro
Junit 5
43 Professional Unit Testing – Test Design Guidelines
@Test
public void assertException() {
IllegalArgumentException ex = assertThrows(
IllegalArgumentException.class,
() -> throwingProdCode());
assertEquals(FILE_LOCKED, ex.getErrorCode());
}
VictorRentea.ro
for loop
Testing a set of input-output pairs?
➔ Parameterized Unit Tests 
➔ .feature files 
46 Professional Unit Testing – Test Design Guidelines
WHY?!
VictorRentea.roProfessional Unit Testing – Test Design Guidelines
@RunWith(Parameterized.class)
public class FizzBuzzTest {
private final int number;
private final String expected;
public FizzBuzzTest(int number, String expected) {
this.number = number;
this.expected = expected;
}
@Parameters(name="For {0}, returns "{1}"")
public static List<Object[]> getParameters() {
return asList(
new Object[] {1, "1"},
new Object[] {2, "2"},
new Object[] {5, "Buzz"},
new Object[] {3*5, "Fizz Buzz"},
new Object[] {3*7, "Fizz Wizz"},
[...]
);
}
@Test
public void checkNumber() {
assertEquals(expected, FizzBuzz.getNumber(number));
}
}
(instead of asserting in a loop)
ParameterizedTests
47
VictorRentea.ro
Can be signed directly by Biz guys !
.feature files
48
VictorRentea.ro
multi-thread
Looking for a race bug with sleep(random) ?
➔ Use-Your-Brain™ instead 
51 Professional Unit Testing – Test Design Guidelines
asserting time
random
Testing to find errors?
➔ replay real calls from production 
(Even more: Golden Master Technique)
VictorRentea.ro52 Professional Unit Testing – Test Design Guidelines
dependencies
TimeMachine.setTestClockAt(time);
actual = callProd(…);
assertEquals(new Date(), actual);
assertEquals(time, actual);
fails/passes randomly!
return TimeMachine.now();
return new Date();
return LocalDateTime.now();+1ms?
asserting time
your custom class
Let's truncate! :D
draconian
PowerMock?
VictorRentea.ro53 Professional Unit Testing – Test Design Guidelines
Tests Can
Control the Time
VictorRentea.ro
databases
56 Professional Unit Testing – Test Design Guidelines
files
queues
external web services
These are Integration Tests
VictorRentea.ro
GREEN
ZONE
Integration vs Unit Tests
57 Professional Unit Testing – Test Design Guidelines
Deep Testing
through many layers
Fragile
(DB, files, external systems)
Their failure is not always a bug
Super-Fast
100 tests/sec
(some can be slower)
Slow
start-up
the container
In-mem DB
VictorRentea.ro
Sensitive
High Coverage %
Correct Tests
Specific
Expressive
Isolated & Robust
Low overlap
Fast
Few
Small, DRY tests
Test Design Goals
60 Professional Unit Testing – Principles of Test Design
VictorRentea.ro
Minimize Duplication
61
public void myTestRaw() {
Order o = new Order();
o.setDate(new Date());
o.setLines(new ArrayList<OrderLine>());
OrderLine ol1 = new OrderLine();
ol1.setProduct("P1");
ol1.setItems(3);
o.getLines().add(ol1);
OrderLine ol2 = new OrderLine();
ol2.setProduct("P2");
ol2.setItems(null);
o.getLines().add(ol2);
target.process(o);
}
Data Initialization
VictorRentea.ro66 Professional Unit Testing – Test Design Guidelines
public void myTestWithBuildersAndObjectMother() {
Order o = anOrderWithOneLine()
.with(anOrderLine().withItem(anItem()))
.build();
target.process(o);
}
Fluent Builder
Object Mother
VictorRentea.ro
▪Fluent Builder®
▪Factory methods
- Object Mother shared between tests ?
▪Wrap production API
- In a more testable API
▪Keep common stuff in fields
▪Shared @Before
DRY Tests
67 Professional Unit Testing – Test Design Guidelines
Safe
Each @Test runs on a
fresh instance of the Test class
VictorRentea.ro
Sensitive
High Coverage %
Correct Tests
Specific
Expressive
Isolated & Robust
Low overlap
Fast
Few
Small, DRY tests
Test Design Goals
68 Professional Unit Testing – Principles of Test Design
VictorRentea.ro
@Before
You want to shrink a large test
Abusing @Before
==Practical Guide☺==
69 Professional Unit Testing – Test Design Guidelines
You move some code in the @Before
▪ Data initialization
▪ Mocks
▪ Infra setup: DB, ..
Other tests do the same:
And time passes by
When you read a test:
▪ Arrange = method + @Before
▪ What part of it ?
VictorRentea.ro
SingleTestClass ATest
BTest
Fixture-Based Test Breakdown
70 Professional Unit Testing – Test Design
@Before
Nested Test Fixtures in JUnit5:
https://junit.org/junit5/docs/current/user-guide/#writing-tests-nested
@Test
@Test
@Test
sharedA
@Test
@Test
@Test
@Test
@Test
@Before
@Test
@Test
@Test
@Test
@Test
@Test
@Test
@Test
@Before
sharedB
VictorRentea.ro
Start with one Test class/Prod class
- If it grows (>300 lines?) or
- If many tests share a fixture
Split it
71 Professional Unit Testing – Test Design Guidelines
RecordRepositoryTest
RecordRepositorySearchForVersionTest
Maybe also split
the prod code ?
VictorRentea.ro
5-10 lines
Descriptive names
Test Methods
72 Professional Unit Testing – Test Design Guidelines
public void givenAnInactiveCustomer_whenHePlacesAnOrder_itIsActivated()
public void getRecordDeltasForVersionWithDeletedRecord()
public void givenAProgramLinkedTo2Records_whenUpdated_2AuditsAreInserted(
RecordRowValidatorTest.invalidRecordStartDateFormat()
VictorRentea.ro
AnInactiveCustomerShould
.beActivatedWhenHePlacesAnOrder()
A Naming Convention
73 Professional Unit Testing – Test Design Guidelines
"Given" = the class name
~ @Before
No need for method prefixes
Test names start with "Then" part
the expectations
"When" follows
https://codurance.com/2014/12/13/naming-test-classes-and-methods/
VictorRentea.ro
Expressive Tests
74
Superb Failures
VictorRentea.ro
Suggestive Literals
75 Professional Unit Testing – Test Design Guidelines
@Test
public void customerEmailIsUpdated() {
Long customerId = createCustomer(new Customer("oldPhone"));
updateCustomerPhone(customerId, "newPhone");
Customer updatedCustomer = getCustomer(customerId);
assertEquals("newPhone", updatedCustomer.getPhone());
}
VictorRentea.ro
Assert a collection
Beautiful Failure Messages
(an example)
76 Professional Unit Testing – Test Design Guidelines
assertEquals(1, names.size());
assertEquals("name", names.iterator().next());
assertEquals(Collections.singleton("name"), names);
vs
VictorRentea.ro
Try to name this test:
➔ Break it in 2 tests 
(perhaps break the Prod too? ~ CQS)
Single Assert Rule
one feature/test
77 Professional Unit Testing – Test Design Guidelines
assertEquals("FN", customer.getFirstName());
assertEquals("LN", customer.getLastName());
assertEquals(Status.SUCCESS, result);
verify(emailService).sendEmail(anyObject());
VictorRentea.ro
Sensitive
High Coverage %
Correct Tests
Specific
Expressive
Isolated & Robust
Low overlap
Fast
Few
Small, DRY tests
Test Design Goals
78 Professional Unit Testing – Principles of Test Design
VictorRentea.ro
Should Tests Respect
Encapsulation?
79
VictorRentea.ro
Fresh code:
Test through the public API
Tests won't break when implem changes
Practices the API
Legacy code:
Breaking encapsulation
is a core technique
Temporarily use package/public protection
80 Professional Unit Testing – Test Design Guidelines
VictorRentea.ro
You run your test suite
Test #13 is RED
To debug it, you run it alone:
Test #13 is GREEN
??!!!?!
Yet Another Happy Day#2…
81 Professional Unit Testing – Testing on DB
VictorRentea.ro
You run your test suite
It's GREEN
You add Test #43
Test #13 turns RED
(unchanged!)
You delete Test #43
Test #13 goes back GREEN
Yet Another Happy Day#3…
82 Professional Unit Testing – Testing on DB
??!!!?!
VictorRentea.ro
▪In-memory Objects
▪COMMITs to DB
▪External files/systems
Hidden Test Dependencies
83 Professional Unit Testing – Testing on DB
- Static fields, singletons
- PowerMocks
- Thread Locals
- Container shared by tests [Spring]
- In-memory or external
➔ Reset them in @Before 
VictorRentea.ro
JUnit runs tests in unexpected order
To Ensure Independency
84 Professional Unit Testing – Testing on DB
(DON'T DO THIS)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
VictorRentea.ro
Sensitive
High Coverage %
Correct Tests
Specific
Expressive
Isolated & Robust
Low overlapping
Fast
Few
Small, DRY tests
Test Design Goals
86 Professional Unit Testing – Principles of Test Design
VictorRentea.ro
▪Test Design Principles
▪TDD
▪Mocks
▪Databases
▪Legacy Code
Agenda
87
VictorRentea.ro
A discipline in which
you grow software in small increments
for which you write
the tests before the implementation
TDD
88 Professional Unit Testing – TDD
Credited to Kent Beck, 2003
VictorRentea.ro
TDD Mantra
Red-Green-Refactor
90 Professional Unit Testing – TDD
With Grace
fail
KISS, YAGNI, Golf:
Write as little prod code,
don’t mind about quality
You can't break anything
•Start with the simplest cases
•Start with the ☺ flows
If you get stuck or other tests
break => revert and retry
DRY, Clean Code
Write prod code to
Make It PassWrite a Failing Test
for a new feature
Refactor
prod + tests
pass
fail
Run
Tests
Run
Tests
Run
Tests
1-10 min
Overlapping? –
Incorrect? –
Rules of Simple
Design
VictorRentea.ro
Rules of Simple Design
91 Professional Unit Testing – TDD
- Kent Beck
https://martinfowler.com/bliki/BeckDesignRules.html
2. Reveals Intention
3. No Duplication
4. Fewest Elements
1. Passes the Tests
VictorRentea.ro
TDD Schools of Thought
92 Professional Unit Testing – TDD
TDD as if you meant it
VictorRentea.ro
▪Test Design Principles
▪TDD
▪Mocks
▪Databases
▪Legacy Code
Agenda
101
VictorRentea.ro
Fake Objects
102 Professional Unit Testing – Mocking
Fast
DB ☺
Repeatable
Isolation from external systems
Mentally Simpler
To test a layer, fake the layer bellow:
WHY?!
VictorRentea.ro103
VictorRentea.ro
Fake
104 Professional Unit Testing – Mocking
Mock
Verify a method call
verify(repo).save(…);
Stub
Respond to method calls
when(mock.method())
.thenReturn(…);
The confusion:
VictorRentea.ro
The Circle of Purity
106 Professional Unit Testing – Mocking
VictorRentea.ro
Side-effects
1)On external systems:
2)On in-memory objects
➔ assert their state
What can a Unit Test check?
107 Professional Unit Testing – Mocking
Input OutputFeature
(prod function)
Data from
dependencies
Input+Deps → Output
(real or stubbed)
a)Real: SELECT
b)Mock: verify repo.save() was called
Input → Output
Simple and Elegant
Pure function: 𝑓 𝑥 = 𝑥2
Simplify design:
purify logic
VictorRentea.ro108 Professional Unit Testing – The Circle of Purity
Extract Method
mock
stub
VictorRentea.ro109 Professional Unit Testing – The Circle of Purity
= Pure Function
VictorRentea.ro
infrastructure
domain
side effects
110
pure logic
VictorRentea.ro
Verify every method call
How many times calls happen
times(1)
No extra call happen
Capture-assert every argument
115 Professional Unit Testing – Mocking
VictorRentea.ro116
Minimalistic Testing
VictorRentea.ro
Object
119
query
command
inbound outbound
to self
What to test?
Inspiredfrom:SandiMetz-Themagictricksoftestinghttps://www.youtube.com/watch?v=URSWYvyc42M
VictorRentea.ro
query command
inbound assert assert
to self ignore ignore
outbound ignore verify
Minimalistic Testing
120
Inspiredfrom:SandiMetz-Themagictricksoftestinghttps://www.youtube.com/watch?v=URSWYvyc42M
VictorRentea.ro
Which API is stable?
Yet reachable?
Where to Slice it?
121
A
B
C
D
nearest edge
final real system
intermediary
TEST
VictorRentea.ro
It may be simpler to test
some classes together!
122
(versus testing them separately using mocks)
VictorRentea.ro127 Professional Unit Testing – Mocking
OrderService
EmailService
PARTIAL MOCK
(normal)MOCK
private sendEmail() public sendEmail()
Separation by Layers of Abstraction
A Tale about the Evil Partial Mock...
Refactor
using
mocks
Which methods
are more abstract ?
(i.e. higher-level)Don’t do that !!
Partial Mocks are Evil ! Oh!.. Why?
Dunno..
@Autowired
Tests
overlap!!
public placeOrder()
public shipOrder()
a.k.a. “spy”
VictorRentea.ro
▪Test Design Principles
▪TDD
▪Mocks
▪Databases
▪Legacy Code
Agenda
141
VictorRentea.ro142 Professional Unit Testing – Recap
First couple of unit tests: Priceless
Test no.
difficulty
@
@
VictorRentea.ro
▪Extract-'n-test
- Then mock it out
▪Break encapsulation
- Expose internal state
- Spy internal methods
▪Hack statics
- PowerMock methods
- Control global state
▪Introduce Seams
- Decoupling places
▪Exploratory refactoring
- 30 mins that you always throw away
- Search for ways to break the design
to become more testable
▪IDE Refactoring only
- When not guarded by tests
- Mob
▪Temporary ugly tests
▪Unit Test + Refactoring
- Always together!
Some Techniques
for Testing Legacy Code
150 Professional Unit Testing – Legacy Code More on: http://blog.adrianbolboaca.ro/2015/02/unit-testing-on-legacy-code/
VictorRentea.ro151
VictorRentea.ro
Testing Legacy Code: Feeling
153 Professional Unit Testing – Recap https://www.youtube.com/watch?v=_gQ84-vWNGU
VictorRentea.ro
Testing Legacy Code
Golden Master Technique
154 Professional Unit Testing – Recap
http://blog.adrianbolboaca.ro/2014/05/golden-master/
original
refactored
same
input
same
output
same interactions
Idea: record these in production,
then replay them on your refactor
VictorRentea.ro
▪ Clean Code + Clean Coders Videos [CCEp#] http://www.cleancoders.com/
Robert C. Martin (Uncle Bob)
▪ (London-Style TDD): Growing Object-Oriented Software, Guided by Tests
Steve Freeman, Nat Pryce, 2009
▪ (Classic-Style TDD): Test-Driven Development, by example
Kent Beck, 2000
▪ The Art of Unit Testing
Roy Osherove, 2009
▪ Coding Dojo Handbook
Emily Bache, 2009
▪ https://springtestdbunit.github.io/spring-test-dbunit/faq.html
▪ Professional TDD with C#: Developing Real World Apps with TDD
James Bender, Jeff McWherter, 2011
▪ Agile in a Flash: https://pragprog.com/book/olag/agile-in-a-flash
▪ "Is TDD Dead?" - on You Tube
▪ Introducing BDD: http://dannorth.net/introducing-bdd/
Dan North
▪ Refactoring
Martin Fowler, 1999
References
156 Professional Unit Testing – Further Reading
VictorRentea.ro
▪Test where the Fear is
▪Correct Tests fail  Prod mutates
▪Explicit, Simple Tests
▪TODO: Try TDD!
▪Purify the heavy logic
▪Listen to Tests: Testable Design
Key Points
157
VictorRentea.ro158
End of Part 1
Trainings, talks, goodies Daily posts on
Let's chat!
What do you want after the break?
Proxies; Legacy Kata; TDD; Java8
Vote here: victorrentea.ro/vote
Come take 1 sticker:

Contenu connexe

Tendances

The Art of Clean code
The Art of Clean codeThe Art of Clean code
The Art of Clean codeVictor Rentea
 
Clean Code - The Next Chapter
Clean Code - The Next ChapterClean Code - The Next Chapter
Clean Code - The Next ChapterVictor Rentea
 
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Victor Rentea
 
Software Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdfSoftware Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdfVictor Rentea
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best PracticesTheo Jungeblut
 
The Proxy Fairy, and The Magic of Spring Framework
The Proxy Fairy, and The Magic of Spring FrameworkThe Proxy Fairy, and The Magic of Spring Framework
The Proxy Fairy, and The Magic of Spring FrameworkVictor Rentea
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionsaber tabatabaee
 
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteClean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteVictor Rentea
 
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's GuideEvolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's GuideVictor Rentea
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And MockingJoe Wilson
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the DomainVictor Rentea
 
Extreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipExtreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipVictor Rentea
 
Finally, easy integration testing with Testcontainers
Finally, easy integration testing with TestcontainersFinally, easy integration testing with Testcontainers
Finally, easy integration testing with TestcontainersRudy De Busscher
 

Tendances (20)

The Art of Clean code
The Art of Clean codeThe Art of Clean code
The Art of Clean code
 
Clean code
Clean codeClean code
Clean code
 
Clean Code - The Next Chapter
Clean Code - The Next ChapterClean Code - The Next Chapter
Clean Code - The Next Chapter
 
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
 
Software Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdfSoftware Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdf
 
Clean Code
Clean CodeClean Code
Clean Code
 
Clean Code
Clean CodeClean Code
Clean Code
 
Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
 
Clean Code
Clean CodeClean Code
Clean Code
 
The Proxy Fairy, and The Magic of Spring Framework
The Proxy Fairy, and The Magic of Spring FrameworkThe Proxy Fairy, and The Magic of Spring Framework
The Proxy Fairy, and The Magic of Spring Framework
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
 
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteClean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
 
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's GuideEvolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the Domain
 
Extreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipExtreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software Craftsmanship
 
Clean code
Clean codeClean code
Clean code
 
Finally, easy integration testing with Testcontainers
Finally, easy integration testing with TestcontainersFinally, easy integration testing with Testcontainers
Finally, easy integration testing with Testcontainers
 

Similaire à Unit Testing like a Pro - The Circle of Purity

Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testingdn
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testingmalcolmt
 
6 Traits of a Successful Test Automation Architecture
6 Traits of a Successful Test Automation Architecture6 Traits of a Successful Test Automation Architecture
6 Traits of a Successful Test Automation ArchitectureErdem YILDIRIM
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Ukraine
 
(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and back(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and backDavid Rodenas
 
Testing, Learning and Professionalism — 20171214
Testing, Learning and Professionalism — 20171214Testing, Learning and Professionalism — 20171214
Testing, Learning and Professionalism — 20171214David Rodenas
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit testEugenio Lentini
 
How I Learned to Stop Worrying and Love Legacy Code
How I Learned to Stop Worrying and Love Legacy CodeHow I Learned to Stop Worrying and Love Legacy Code
How I Learned to Stop Worrying and Love Legacy CodeGene Gotimer
 
Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)Peter Kofler
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017Xavi Hidalgo
 
Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Fwdays
 
Keynote AST 2016
Keynote AST 2016Keynote AST 2016
Keynote AST 2016Kim Herzig
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionDionatan default
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easierChristian Hujer
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkPeter Kofler
 

Similaire à Unit Testing like a Pro - The Circle of Purity (20)

Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testing
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testing
 
6 Traits of a Successful Test Automation Architecture
6 Traits of a Successful Test Automation Architecture6 Traits of a Successful Test Automation Architecture
6 Traits of a Successful Test Automation Architecture
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
 
(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and back(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and back
 
Testing, Learning and Professionalism — 20171214
Testing, Learning and Professionalism — 20171214Testing, Learning and Professionalism — 20171214
Testing, Learning and Professionalism — 20171214
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
How I Learned to Stop Worrying and Love Legacy Code
How I Learned to Stop Worrying and Love Legacy CodeHow I Learned to Stop Worrying and Love Legacy Code
How I Learned to Stop Worrying and Love Legacy Code
 
Continuous Testing
Continuous TestingContinuous Testing
Continuous Testing
 
Test Driven
Test DrivenTest Driven
Test Driven
 
Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"
 
Testing 101
Testing 101Testing 101
Testing 101
 
Keynote AST 2016
Keynote AST 2016Keynote AST 2016
Keynote AST 2016
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 
Getting Started With Testing
Getting Started With TestingGetting Started With Testing
Getting Started With Testing
 

Plus de Victor Rentea

Microservice Resilience Patterns @VoxxedCern'24
Microservice Resilience Patterns @VoxxedCern'24Microservice Resilience Patterns @VoxxedCern'24
Microservice Resilience Patterns @VoxxedCern'24Victor Rentea
 
Distributed Consistency.pdf
Distributed Consistency.pdfDistributed Consistency.pdf
Distributed Consistency.pdfVictor Rentea
 
Testing Microservices @DevoxxBE 23.pdf
Testing Microservices @DevoxxBE 23.pdfTesting Microservices @DevoxxBE 23.pdf
Testing Microservices @DevoxxBE 23.pdfVictor Rentea
 
From Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptxFrom Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptxVictor Rentea
 
Test-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxTest-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxVictor Rentea
 
Profiling your Java Application
Profiling your Java ApplicationProfiling your Java Application
Profiling your Java ApplicationVictor Rentea
 
Vertical Slicing Architectures
Vertical Slicing ArchitecturesVertical Slicing Architectures
Vertical Slicing ArchitecturesVictor Rentea
 
Unit testing - 9 design hints
Unit testing - 9 design hintsUnit testing - 9 design hints
Unit testing - 9 design hintsVictor Rentea
 
Refactoring blockers and code smells @jNation 2021
Refactoring   blockers and code smells @jNation 2021Refactoring   blockers and code smells @jNation 2021
Refactoring blockers and code smells @jNation 2021Victor Rentea
 
Hibernate and Spring - Unleash the Magic
Hibernate and Spring - Unleash the MagicHibernate and Spring - Unleash the Magic
Hibernate and Spring - Unleash the MagicVictor Rentea
 
Integration testing with spring @JAX Mainz
Integration testing with spring @JAX MainzIntegration testing with spring @JAX Mainz
Integration testing with spring @JAX MainzVictor Rentea
 
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021Victor Rentea
 
Pure functions and immutable objects @dev nexus 2021
Pure functions and immutable objects @dev nexus 2021Pure functions and immutable objects @dev nexus 2021
Pure functions and immutable objects @dev nexus 2021Victor Rentea
 
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...Victor Rentea
 
Pure Functions and Immutable Objects
Pure Functions and Immutable ObjectsPure Functions and Immutable Objects
Pure Functions and Immutable ObjectsVictor Rentea
 
Definitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in JavaDefinitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in JavaVictor Rentea
 
Extreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipExtreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipVictor Rentea
 
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...Victor Rentea
 

Plus de Victor Rentea (20)

Microservice Resilience Patterns @VoxxedCern'24
Microservice Resilience Patterns @VoxxedCern'24Microservice Resilience Patterns @VoxxedCern'24
Microservice Resilience Patterns @VoxxedCern'24
 
Distributed Consistency.pdf
Distributed Consistency.pdfDistributed Consistency.pdf
Distributed Consistency.pdf
 
Testing Microservices @DevoxxBE 23.pdf
Testing Microservices @DevoxxBE 23.pdfTesting Microservices @DevoxxBE 23.pdf
Testing Microservices @DevoxxBE 23.pdf
 
From Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptxFrom Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptx
 
Test-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxTest-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptx
 
Profiling your Java Application
Profiling your Java ApplicationProfiling your Java Application
Profiling your Java Application
 
OAuth in the Wild
OAuth in the WildOAuth in the Wild
OAuth in the Wild
 
Vertical Slicing Architectures
Vertical Slicing ArchitecturesVertical Slicing Architectures
Vertical Slicing Architectures
 
Unit testing - 9 design hints
Unit testing - 9 design hintsUnit testing - 9 design hints
Unit testing - 9 design hints
 
Refactoring blockers and code smells @jNation 2021
Refactoring   blockers and code smells @jNation 2021Refactoring   blockers and code smells @jNation 2021
Refactoring blockers and code smells @jNation 2021
 
Hibernate and Spring - Unleash the Magic
Hibernate and Spring - Unleash the MagicHibernate and Spring - Unleash the Magic
Hibernate and Spring - Unleash the Magic
 
Integration testing with spring @JAX Mainz
Integration testing with spring @JAX MainzIntegration testing with spring @JAX Mainz
Integration testing with spring @JAX Mainz
 
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
 
Pure functions and immutable objects @dev nexus 2021
Pure functions and immutable objects @dev nexus 2021Pure functions and immutable objects @dev nexus 2021
Pure functions and immutable objects @dev nexus 2021
 
TDD Mantra
TDD MantraTDD Mantra
TDD Mantra
 
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
 
Pure Functions and Immutable Objects
Pure Functions and Immutable ObjectsPure Functions and Immutable Objects
Pure Functions and Immutable Objects
 
Definitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in JavaDefinitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in Java
 
Extreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software CraftsmanshipExtreme Professionalism - Software Craftsmanship
Extreme Professionalism - Software Craftsmanship
 
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
 

Dernier

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 

Dernier (20)

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 

Unit Testing like a Pro - The Circle of Purity

  • 1. VictorRentea.ro The Art of Unit Testing The Circle of Purity VictorRentea.ro Independent Trainer Lead Architect at IBM
  • 2. When something is painful but you can't avoid doing it… postpone it
  • 3. When something is painful but you can't avoid doing it… delegate it
  • 4. When something is painful but you can't avoid doing it… Do It More Often! "Bring The Pain Forward!"
  • 5. Continuous Integration Pair Programming Continuous Refactoring TDD XP "Bring The Pain Forward!"
  • 6.
  • 7. Victor Rentea 14 years of Java Clean Code Evangelist VictorRentea.ro 30+ talks, 12 meetups .NET Lead Architect Tech Team Lead and Consultant Software Craftsman XP: Pair Programming, Refactoring, TDD
  • 8. VictorRentea.ro @victorrentea victor.rentea@gmail.com Independent Technical Trainer & Coach HibernateSpring Java 8 Architecture, DDDDesign Patterns Clean Code Unit Testing, TDD Java Performance and much more…Scala 180+ days1300 devs6 years VictorRentea.rovictor.rentea@gmail.com 30 companies Posting daily on
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 15. VictorRentea.ro ▪Arrange: setup the test fixture ▪Act: call the production code ▪Assert the outcomes ▪Annihilate[opt]: clean up Terms 16 Professional Unit Testing – Basics
  • 17. VictorRentea.ro Full: https://www.youtube.com/watch?v=GvAzrC6-spQ Why do we Write Tests ? 18 Professional Unit Testing – Basics Uncle Bob on TDD Shorter: https://youtu.be/GvAzrC6-spQ?t=116 1:48
  • 18. VictorRentea.ro19 Professional Unit Testing – Intro To Read-the-Spec™ (before we finish the implem☺) Why do we Write Tests ? FEAR
  • 19. VictorRentea.ro Medical Screening 20 Professional Unit Testing – Principles of Test Design
  • 21. VictorRentea.ro Sensitive High Coverage % Correct Tests Specific Expressive Isolated & Robust Low overlap Fast Few Small, DRY tests Test Design Goals 22 Professional Unit Testing – Principles of Test Design = Maintainable fail for any bug precise failures
  • 22. VictorRentea.ro Test code >> Prod code Not maintainable? Under pressure, devs might: 23 Professional Unit Testing – Principles of Test Design @Ignore delete test delete asserts // comment test invert asserts // @Test
  • 24. VictorRentea.ro ▪Code that you fear 😱 (hard to understand) ▪A distant corner in the logic (takes 3 mins of UI clicks to reproduce) ▪A bug (before fixing it) 🏆 ▪for/if/while ⚙ ▪Thrown exception ▪A method that just calls two others ▪Trivial code ▪Legacy code with 0 bugs, 0 changes (over the last year) Testing Priorities 25 Professional Unit Testing – Basics PRIORITY a.setName(b.getName()); *in case you're not 100% TDD
  • 25. VictorRentea.ro Tests are green. You implement a huge CR in Prod code. Tests are green. Evergreen Tests 26 We ❤ Green Tests!
  • 29. VictorRentea.ro30 How can you check that your test really covers what it says?
  • 30. VictorRentea.ro33 Professional Unit Testing – Test Design Guidelines Mutation Testing You make some change to the Production code You get some "mutant" code The tests should squash the mutant by turning red You run the Tests You undo the change There are frameworks that play like this with your code, but their results might be depressing Tests fail ֞ Production code is altered How can you check that your test really covers what it says?
  • 31. VictorRentea.ro Always see your test failing at least once 34 Tests, like laws, are meant to be broken
  • 32. VictorRentea.ro ▪Regression - Yeehaaa! ➔ fix it ▪Change Request - Double Check ➔ Update/Delete it ? ▪Iso-functional changes - Superficial API Changes ➔ adjust the test - Refactoring internals ➔ loosen the test coupling ▪A Bug in a Test - Usually discovered via debugging ➔ fix the test Why can a Test Fail ? 35 Professional Unit Testing – Test Design Guidelines the usual suspect = production code
  • 33. VictorRentea.ro A Bug in a Test 36 Professional Unit Testing – Test Design Guidelines
  • 34. VictorRentea.ro37 Professional Unit Testing – Test Design Guidelines A Bug in a Test
  • 35. VictorRentea.ro38 Professional Unit Testing – Test Design Guidelines
  • 36. VictorRentea.ro39 Professional Unit Testing – Test Design Guidelines
  • 37. VictorRentea.ro Concatenation, arithmetic 40 Professional Unit Testing – Test Design Guidelines assertEquals("Greetings" + name, logic.getGreetings(name)); if, switch Did you also tested that logic? ("test the tests" ☺) it's missing a " "! Why? The same Dev wrote both prod and test code! ☺ CPP ➔ Prefer literals  assertEquals("Greetings John", logic.getGreetings("John")); Can you find the bug?
  • 38. VictorRentea.ro catch-assert When you want to verify an exception is thrown 41 Professional Unit Testing – Test Design Guidelines try { logicThatShouldThrow(); fail("should have thrown"); } catch (MyException ex) { assert("msg", ex.getMessage()); } Can you find the bug?
  • 39. VictorRentea.ro Verify an Exception Type is Thrown 42 Professional Unit Testing – Test Design Guidelines @Rule public ExpectedException exception = none(); @Test public void expectExceptionWithDetails() { exception.expectMessage("contains this"); // or… exception.expect(exceptionWithCode(FILE_LOCKED)); // throwing code } @Test(expected = IllegalArgumentException.class) public void expectExceptionTypeThrown() { // throwing code } Verify Exception Message/Code For precision: let's create 20 new Exception classes ! Hamcrest
  • 40. VictorRentea.ro Junit 5 43 Professional Unit Testing – Test Design Guidelines @Test public void assertException() { IllegalArgumentException ex = assertThrows( IllegalArgumentException.class, () -> throwingProdCode()); assertEquals(FILE_LOCKED, ex.getErrorCode()); }
  • 41. VictorRentea.ro for loop Testing a set of input-output pairs? ➔ Parameterized Unit Tests  ➔ .feature files  46 Professional Unit Testing – Test Design Guidelines WHY?!
  • 42. VictorRentea.roProfessional Unit Testing – Test Design Guidelines @RunWith(Parameterized.class) public class FizzBuzzTest { private final int number; private final String expected; public FizzBuzzTest(int number, String expected) { this.number = number; this.expected = expected; } @Parameters(name="For {0}, returns "{1}"") public static List<Object[]> getParameters() { return asList( new Object[] {1, "1"}, new Object[] {2, "2"}, new Object[] {5, "Buzz"}, new Object[] {3*5, "Fizz Buzz"}, new Object[] {3*7, "Fizz Wizz"}, [...] ); } @Test public void checkNumber() { assertEquals(expected, FizzBuzz.getNumber(number)); } } (instead of asserting in a loop) ParameterizedTests 47
  • 43. VictorRentea.ro Can be signed directly by Biz guys ! .feature files 48
  • 44. VictorRentea.ro multi-thread Looking for a race bug with sleep(random) ? ➔ Use-Your-Brain™ instead  51 Professional Unit Testing – Test Design Guidelines asserting time random Testing to find errors? ➔ replay real calls from production  (Even more: Golden Master Technique)
  • 45. VictorRentea.ro52 Professional Unit Testing – Test Design Guidelines dependencies TimeMachine.setTestClockAt(time); actual = callProd(…); assertEquals(new Date(), actual); assertEquals(time, actual); fails/passes randomly! return TimeMachine.now(); return new Date(); return LocalDateTime.now();+1ms? asserting time your custom class Let's truncate! :D draconian PowerMock?
  • 46. VictorRentea.ro53 Professional Unit Testing – Test Design Guidelines Tests Can Control the Time
  • 47. VictorRentea.ro databases 56 Professional Unit Testing – Test Design Guidelines files queues external web services These are Integration Tests
  • 48. VictorRentea.ro GREEN ZONE Integration vs Unit Tests 57 Professional Unit Testing – Test Design Guidelines Deep Testing through many layers Fragile (DB, files, external systems) Their failure is not always a bug Super-Fast 100 tests/sec (some can be slower) Slow start-up the container In-mem DB
  • 49. VictorRentea.ro Sensitive High Coverage % Correct Tests Specific Expressive Isolated & Robust Low overlap Fast Few Small, DRY tests Test Design Goals 60 Professional Unit Testing – Principles of Test Design
  • 50. VictorRentea.ro Minimize Duplication 61 public void myTestRaw() { Order o = new Order(); o.setDate(new Date()); o.setLines(new ArrayList<OrderLine>()); OrderLine ol1 = new OrderLine(); ol1.setProduct("P1"); ol1.setItems(3); o.getLines().add(ol1); OrderLine ol2 = new OrderLine(); ol2.setProduct("P2"); ol2.setItems(null); o.getLines().add(ol2); target.process(o); } Data Initialization
  • 51. VictorRentea.ro66 Professional Unit Testing – Test Design Guidelines public void myTestWithBuildersAndObjectMother() { Order o = anOrderWithOneLine() .with(anOrderLine().withItem(anItem())) .build(); target.process(o); } Fluent Builder Object Mother
  • 52. VictorRentea.ro ▪Fluent Builder® ▪Factory methods - Object Mother shared between tests ? ▪Wrap production API - In a more testable API ▪Keep common stuff in fields ▪Shared @Before DRY Tests 67 Professional Unit Testing – Test Design Guidelines Safe Each @Test runs on a fresh instance of the Test class
  • 53. VictorRentea.ro Sensitive High Coverage % Correct Tests Specific Expressive Isolated & Robust Low overlap Fast Few Small, DRY tests Test Design Goals 68 Professional Unit Testing – Principles of Test Design
  • 54. VictorRentea.ro @Before You want to shrink a large test Abusing @Before ==Practical Guide☺== 69 Professional Unit Testing – Test Design Guidelines You move some code in the @Before ▪ Data initialization ▪ Mocks ▪ Infra setup: DB, .. Other tests do the same: And time passes by When you read a test: ▪ Arrange = method + @Before ▪ What part of it ?
  • 55. VictorRentea.ro SingleTestClass ATest BTest Fixture-Based Test Breakdown 70 Professional Unit Testing – Test Design @Before Nested Test Fixtures in JUnit5: https://junit.org/junit5/docs/current/user-guide/#writing-tests-nested @Test @Test @Test sharedA @Test @Test @Test @Test @Test @Before @Test @Test @Test @Test @Test @Test @Test @Test @Before sharedB
  • 56. VictorRentea.ro Start with one Test class/Prod class - If it grows (>300 lines?) or - If many tests share a fixture Split it 71 Professional Unit Testing – Test Design Guidelines RecordRepositoryTest RecordRepositorySearchForVersionTest Maybe also split the prod code ?
  • 57. VictorRentea.ro 5-10 lines Descriptive names Test Methods 72 Professional Unit Testing – Test Design Guidelines public void givenAnInactiveCustomer_whenHePlacesAnOrder_itIsActivated() public void getRecordDeltasForVersionWithDeletedRecord() public void givenAProgramLinkedTo2Records_whenUpdated_2AuditsAreInserted( RecordRowValidatorTest.invalidRecordStartDateFormat()
  • 58. VictorRentea.ro AnInactiveCustomerShould .beActivatedWhenHePlacesAnOrder() A Naming Convention 73 Professional Unit Testing – Test Design Guidelines "Given" = the class name ~ @Before No need for method prefixes Test names start with "Then" part the expectations "When" follows https://codurance.com/2014/12/13/naming-test-classes-and-methods/
  • 60. VictorRentea.ro Suggestive Literals 75 Professional Unit Testing – Test Design Guidelines @Test public void customerEmailIsUpdated() { Long customerId = createCustomer(new Customer("oldPhone")); updateCustomerPhone(customerId, "newPhone"); Customer updatedCustomer = getCustomer(customerId); assertEquals("newPhone", updatedCustomer.getPhone()); }
  • 61. VictorRentea.ro Assert a collection Beautiful Failure Messages (an example) 76 Professional Unit Testing – Test Design Guidelines assertEquals(1, names.size()); assertEquals("name", names.iterator().next()); assertEquals(Collections.singleton("name"), names); vs
  • 62. VictorRentea.ro Try to name this test: ➔ Break it in 2 tests  (perhaps break the Prod too? ~ CQS) Single Assert Rule one feature/test 77 Professional Unit Testing – Test Design Guidelines assertEquals("FN", customer.getFirstName()); assertEquals("LN", customer.getLastName()); assertEquals(Status.SUCCESS, result); verify(emailService).sendEmail(anyObject());
  • 63. VictorRentea.ro Sensitive High Coverage % Correct Tests Specific Expressive Isolated & Robust Low overlap Fast Few Small, DRY tests Test Design Goals 78 Professional Unit Testing – Principles of Test Design
  • 65. VictorRentea.ro Fresh code: Test through the public API Tests won't break when implem changes Practices the API Legacy code: Breaking encapsulation is a core technique Temporarily use package/public protection 80 Professional Unit Testing – Test Design Guidelines
  • 66. VictorRentea.ro You run your test suite Test #13 is RED To debug it, you run it alone: Test #13 is GREEN ??!!!?! Yet Another Happy Day#2… 81 Professional Unit Testing – Testing on DB
  • 67. VictorRentea.ro You run your test suite It's GREEN You add Test #43 Test #13 turns RED (unchanged!) You delete Test #43 Test #13 goes back GREEN Yet Another Happy Day#3… 82 Professional Unit Testing – Testing on DB ??!!!?!
  • 68. VictorRentea.ro ▪In-memory Objects ▪COMMITs to DB ▪External files/systems Hidden Test Dependencies 83 Professional Unit Testing – Testing on DB - Static fields, singletons - PowerMocks - Thread Locals - Container shared by tests [Spring] - In-memory or external ➔ Reset them in @Before 
  • 69. VictorRentea.ro JUnit runs tests in unexpected order To Ensure Independency 84 Professional Unit Testing – Testing on DB (DON'T DO THIS) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
  • 70. VictorRentea.ro Sensitive High Coverage % Correct Tests Specific Expressive Isolated & Robust Low overlapping Fast Few Small, DRY tests Test Design Goals 86 Professional Unit Testing – Principles of Test Design
  • 72. VictorRentea.ro A discipline in which you grow software in small increments for which you write the tests before the implementation TDD 88 Professional Unit Testing – TDD Credited to Kent Beck, 2003
  • 73. VictorRentea.ro TDD Mantra Red-Green-Refactor 90 Professional Unit Testing – TDD With Grace fail KISS, YAGNI, Golf: Write as little prod code, don’t mind about quality You can't break anything •Start with the simplest cases •Start with the ☺ flows If you get stuck or other tests break => revert and retry DRY, Clean Code Write prod code to Make It PassWrite a Failing Test for a new feature Refactor prod + tests pass fail Run Tests Run Tests Run Tests 1-10 min Overlapping? – Incorrect? – Rules of Simple Design
  • 74. VictorRentea.ro Rules of Simple Design 91 Professional Unit Testing – TDD - Kent Beck https://martinfowler.com/bliki/BeckDesignRules.html 2. Reveals Intention 3. No Duplication 4. Fewest Elements 1. Passes the Tests
  • 75. VictorRentea.ro TDD Schools of Thought 92 Professional Unit Testing – TDD TDD as if you meant it
  • 77. VictorRentea.ro Fake Objects 102 Professional Unit Testing – Mocking Fast DB ☺ Repeatable Isolation from external systems Mentally Simpler To test a layer, fake the layer bellow: WHY?!
  • 79. VictorRentea.ro Fake 104 Professional Unit Testing – Mocking Mock Verify a method call verify(repo).save(…); Stub Respond to method calls when(mock.method()) .thenReturn(…); The confusion:
  • 80. VictorRentea.ro The Circle of Purity 106 Professional Unit Testing – Mocking
  • 81. VictorRentea.ro Side-effects 1)On external systems: 2)On in-memory objects ➔ assert their state What can a Unit Test check? 107 Professional Unit Testing – Mocking Input OutputFeature (prod function) Data from dependencies Input+Deps → Output (real or stubbed) a)Real: SELECT b)Mock: verify repo.save() was called Input → Output Simple and Elegant Pure function: 𝑓 𝑥 = 𝑥2 Simplify design: purify logic
  • 82. VictorRentea.ro108 Professional Unit Testing – The Circle of Purity Extract Method mock stub
  • 83. VictorRentea.ro109 Professional Unit Testing – The Circle of Purity = Pure Function
  • 85. VictorRentea.ro Verify every method call How many times calls happen times(1) No extra call happen Capture-assert every argument 115 Professional Unit Testing – Mocking
  • 87. VictorRentea.ro Object 119 query command inbound outbound to self What to test? Inspiredfrom:SandiMetz-Themagictricksoftestinghttps://www.youtube.com/watch?v=URSWYvyc42M
  • 88. VictorRentea.ro query command inbound assert assert to self ignore ignore outbound ignore verify Minimalistic Testing 120 Inspiredfrom:SandiMetz-Themagictricksoftestinghttps://www.youtube.com/watch?v=URSWYvyc42M
  • 89. VictorRentea.ro Which API is stable? Yet reachable? Where to Slice it? 121 A B C D nearest edge final real system intermediary TEST
  • 90. VictorRentea.ro It may be simpler to test some classes together! 122 (versus testing them separately using mocks)
  • 91. VictorRentea.ro127 Professional Unit Testing – Mocking OrderService EmailService PARTIAL MOCK (normal)MOCK private sendEmail() public sendEmail() Separation by Layers of Abstraction A Tale about the Evil Partial Mock... Refactor using mocks Which methods are more abstract ? (i.e. higher-level)Don’t do that !! Partial Mocks are Evil ! Oh!.. Why? Dunno.. @Autowired Tests overlap!! public placeOrder() public shipOrder() a.k.a. “spy”
  • 93. VictorRentea.ro142 Professional Unit Testing – Recap First couple of unit tests: Priceless Test no. difficulty
  • 94.
  • 95. @
  • 96. @
  • 97.
  • 98.
  • 99. VictorRentea.ro ▪Extract-'n-test - Then mock it out ▪Break encapsulation - Expose internal state - Spy internal methods ▪Hack statics - PowerMock methods - Control global state ▪Introduce Seams - Decoupling places ▪Exploratory refactoring - 30 mins that you always throw away - Search for ways to break the design to become more testable ▪IDE Refactoring only - When not guarded by tests - Mob ▪Temporary ugly tests ▪Unit Test + Refactoring - Always together! Some Techniques for Testing Legacy Code 150 Professional Unit Testing – Legacy Code More on: http://blog.adrianbolboaca.ro/2015/02/unit-testing-on-legacy-code/
  • 101. VictorRentea.ro Testing Legacy Code: Feeling 153 Professional Unit Testing – Recap https://www.youtube.com/watch?v=_gQ84-vWNGU
  • 102. VictorRentea.ro Testing Legacy Code Golden Master Technique 154 Professional Unit Testing – Recap http://blog.adrianbolboaca.ro/2014/05/golden-master/ original refactored same input same output same interactions Idea: record these in production, then replay them on your refactor
  • 103. VictorRentea.ro ▪ Clean Code + Clean Coders Videos [CCEp#] http://www.cleancoders.com/ Robert C. Martin (Uncle Bob) ▪ (London-Style TDD): Growing Object-Oriented Software, Guided by Tests Steve Freeman, Nat Pryce, 2009 ▪ (Classic-Style TDD): Test-Driven Development, by example Kent Beck, 2000 ▪ The Art of Unit Testing Roy Osherove, 2009 ▪ Coding Dojo Handbook Emily Bache, 2009 ▪ https://springtestdbunit.github.io/spring-test-dbunit/faq.html ▪ Professional TDD with C#: Developing Real World Apps with TDD James Bender, Jeff McWherter, 2011 ▪ Agile in a Flash: https://pragprog.com/book/olag/agile-in-a-flash ▪ "Is TDD Dead?" - on You Tube ▪ Introducing BDD: http://dannorth.net/introducing-bdd/ Dan North ▪ Refactoring Martin Fowler, 1999 References 156 Professional Unit Testing – Further Reading
  • 104. VictorRentea.ro ▪Test where the Fear is ▪Correct Tests fail  Prod mutates ▪Explicit, Simple Tests ▪TODO: Try TDD! ▪Purify the heavy logic ▪Listen to Tests: Testable Design Key Points 157
  • 105. VictorRentea.ro158 End of Part 1 Trainings, talks, goodies Daily posts on Let's chat! What do you want after the break? Proxies; Legacy Kata; TDD; Java8 Vote here: victorrentea.ro/vote Come take 1 sticker: