In unit testing, what's a unit? Is it a method? Is it a class? Is it a module? No. Let's clarify this once and for all.

In unit testing, a unit isn't an element of structure. In unit testing, a unit is an individually observable element of BEHAVIOR.

#TDD #BDD #ATDD #UnitTesting
BTW I use @mfeathers explanation that "unit tests are tests that run fast" as a possible valid (foundation/element of a) definition of the term unit test.
Stop arguing which element of structure is meant by unit. Unit does not denote an element of structure. It denotes an element of behavior.

And that shouldn't be surprising: Tests are executable specifications of required BEHAVIOR (NOT: STRUCTURE) by example.
So the full definition of unit test is: "Unit tests are fast executable specifications of required behavior by example."
BTW this also means that a 1:1 association with framework and test style, like Cucumber - not unit test, JUnit - unit test, is wrong.

If you use JUnit but your tests are slow, they are not unit tests.
If you use Cucumber, and your tests are fast, they might be unit tests.
Side note: I like to use Cucumber not only for acceptance testing but also for unit testing, especially in those situations where the unit directly implements behavior that I want to describe for or discuss with other humans in pure business language instead of programming.
We can, of course, not write unit tests purely on behavior. Behavior is inaccessible without an element of structure that exposes behavior to make it accessible.

An element of structure that exposes behavior to make it accessible is called "interface".
But unit tests should not couple to more structure than necessary. Their means is not to verify structure. Their usage of structure serves only a few purposes:
• Access behavior for verification
• Unit interface documention
• Decoupling to make them fast
• Fault injection
Refactoring means a change to the structure of source code without changing the required behavior. The latter is specified by the tests.

Unit tests shall support us with refactoring by providing a safety net so we change structure without accidentally changing required behavior.
Unit tests that are too knowledgable about structure make refactoring expensive. The more that unit tests know about structure, the more the unit tests have to change as well when we change structure. This is a negative impact in at least two ways.
The first negative impact is that refactoring becomes more effort. Not only do we have to - intention - change the structure of the production code, but now we also have to change the structure of the test code.
The second negative impact is worse. When we change tests at the same time, and the change is non-trivial, we might, by accident, impact the means of verification of behavior of the test.
Summary: "Unit" in "Unit Test" means unit of behavior (not unit of structure). Structure may change due to refactoring. Keep risk out of refactoring by having unit tests. Keep effort and risk out of refactoring by not coupling your unit tests to structure more than necessary.
BTW: Yes, this also means that Chicago/Detroit (Stateism) wins over London (Mockism) when all other parameters are equivalent because mocks introduce potentially harmful coupling to structure, and that makes future change more difficult/expensive. Slide by @pragdave Image

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Christian Hujer #BLM 🏴‍☠️🖦🧙🏻‍♂️🕊

Christian Hujer #BLM 🏴‍☠️🖦🧙🏻‍♂️🕊 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @christianhujer

2 Feb
Agile is much more about reducing lead time, defects, and all kinds of wastes by empiricism (feedback; transparency, inspection, adaptation) on all various scales of time (from seconds to months) than any particular method or framework.
Your practices, methods, and frameworks should be aligned with this: Check where you are, decide where you want to be, go a small step in that direction, look at how that worked, and repeat. Establish that cycle on various time scales.
On the cycle of seconds, we can use editor-based static code analysis, pair programming, and ensemble programming, to get instant feedback on code while code is written.
Read 10 tweets
2 Feb
It seems it's that time again to clear up some misconceptions about DevOps. A thread.
DevOps means Development Operations. If your team isn't doing both, development and operations of the same product/project, it's not DevOps.
DevOps is not about tools but about mindset. Using Docker, Kubernetes, Helm Charts, Packer, Terraform, etc, does not make you DevOps. Having the same team performing development and operations does.
Read 13 tweets
16 Aug 20
Today is rant day. Let me see what I've got.

Scrum is bullshit. Skip it. Directly move to XP.
Warning: occasional strong language ahead.

Scrum is all about empiricism. Empiricism is good. Empiricism is usually not the problem. In fact, Scrum can even increase the problem.
So you know you have a problem. You can't react to change fast enough. Empiricism isn't helpful: it will only tell you what you already know: that you can't react to change fast enough.
Read 18 tweets
26 May 20
Are you ready for a little thread on a few aspects of software (re-)design, sparkled with inspirational quotes around the topic?

Let's go!
"Life is really simple, but we insist on making it complicated."
― Confucius
When we get the chance for a (rewrite or re-)design, there is a temptation that we should resist, from a technical perspective as well as from a business perspective. That temptation is to equate "better" with "more". And that's wrong.
Read 18 tweets
1 Nov 19
The fundamental vim ideas:
• Commands come in sequences. Having a command mode allows commands with fewer keystrokes and fewer modifier keys to make you more efficient. Also, move away less from the touch typing homerow.
• Commands are mnemonic. For example, z for folding...
...z looks like a sheet of paper when folded.
Why hjkl? Touch typing homerow. Of that, h is left, l is right. The shape j goes down, k goes up. I don't remember specifically what hjkl do, I just remember that the whole editor is mnemonic. That way I remember more with less.
• Repetition. All normal commands can be combined with ranges and counts.
Read 11 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(