[go: up one dir, main page]

0% found this document useful (0 votes)
61 views1 page

Cheat Sheet Unit Testing 1635173296

Unit testing involves writing tests to validate individual units or components of code. There are different types of objects used in unit tests including dummies, fakes, stubs, and mocks. Unit tests should have three key characteristics - they are low-level, written by programmers, and expected to be fast. Code coverage metrics show the percentage of code covered by tests and should be over 80% for core code. Best practices for unit tests include having one assert per test and avoiding random inputs or external dependencies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views1 page

Cheat Sheet Unit Testing 1635173296

Unit testing involves writing tests to validate individual units or components of code. There are different types of objects used in unit tests including dummies, fakes, stubs, and mocks. Unit tests should have three key characteristics - they are low-level, written by programmers, and expected to be fast. Code coverage metrics show the percentage of code covered by tests and should be over 80% for core code. Best practices for unit tests include having one assert per test and avoiding random inputs or external dependencies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Unit Testing

One page that gets you started

Know these definitions: Three


Characteristics
Dummy of Unit Tests
Placeholder required to pass the unit. The dummy should (Martin Fowler)
not be accessed during the test.

Fake 1
Object with working implementation - different from
production one. Simplify external dependency setup
complexity.

Stub
Object that holds predefined data used to answer calls
during tests. Provides indirect input to the unit from a low-level, focusing on a small
dependency. part of the software system

Mock 2
Allows mocks to verify method invocation of the unit - for
example service method invoking the repository method.

Spy
Spies use the original implementation. It is a wrapper of
the original, so it records the number of calls, not the input.
usually written by programers
themselves using their regular tools

Code Coverage (Test Coverage):


3
- shows amount of code covered by tests
- used as % metric (>80% coverage)
- useful for core refactoring

Do Don’ts
expected to be significantly
faster than other kinds of tests

Want to know more?


- One assert per test method - Generate random input Check out our website!
- Share setup and fixture - Access network or file
- Multiple test classes per system www.askui.com
class - Use conditions

www.askui.com

You might also like