Do you recall those buzz words like TDD, BDD? Yep, but we know their problems as well!
TDD is too granular. BDD is too coarse-grained.
Unit tests are too chatty. BDD is too abstract.
TDD requires knowledge of implementation details. BDD does not care about implementation at all.
What is in the middle? Integration tests. Let's be Integration driven then! OK, then how to build infrastructure to run Integration tests? Should we start with IaaS first? How to speed up the development and take into account non-foundational requirements like scaling, security borders, isolation, etc. from the very beginning? To answer the questions, we would combine Integration test-based development with serverless (AWS) to solve a typical business task. Based on the example, we would show how to create a solid foundation for further refactoring/refining of the overall solution and concreting it with Unit tests.
Acceptance tests would be left for home exercise ;)
.NET Fest 2019. Сергей Медведев. How serverless makes Integration TDD a reality. Why we do need it.
1. Тема доклада
Тема доклада
Тема доклада
KYIV 2019
How serverless makes Integration TDD a reality.
Why we do need it.
Sergey Medvedev
Enterprise Architect
.NET CONFERENCE #1 IN UKRAINE
3. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Why do we need testing?
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
- Be able to refactor -> can improve code
- To detect bugs early -> can validate solution quickly
- Be confident in code -> do not be afraid of demo
- Be not afraid of code -> be able to refactor
6. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Code dissected
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
10% of code for 90% of cases
– Happy path
90% of code for 10% cases –
Sad and Bad paths
7. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Where to start?
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
Start with Integration test for Happy path!
9. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Part 2. Practice
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
Domain: Block chain
Goal: Be able to find Nonce to complete block
Limitations:
- Too many competitors -> performance
- Unclear final infrastructure -> prototype
Requirements:
- Need highly scalable solution
- Implementation must follow the standard
10. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP .NET CONFERENCE #1 IN UKRAINE KYIV 2019
OK, we need some basic theory
11. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Bitcoin theory.
Simplified
Block chain
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
More details: https://5minuteblockchain.com/2019/05/10/blockchain/
12. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Bitcoin theory.
Simplified
Block structure
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
More details: https://5minuteblockchain.com/2019/05/20/blocks-in-bitcoin/
13. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Bitcoin theory.
Simplified
Block hash and nonce
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
More details: https://en.bitcoin.it/wiki/Block_hashing_algorithm
Bitcoin hash: SHA256(SHA256(Block_Header))
where
- Block_Header is concatenation of HEX’ed values of the following fields
Field Purpose
Version Block version number
hashPrevBlock 256-bit hash of the previous block header
hashMerkleRoot 256-bit hash based on all of the transactions in the block
Time As seconds since 1970-01-01T00:00 UTC
Bits Current difficulty
Nonce
32-bit number (starts at 0, is incremented for each hash.
If Nonce overflows - extraNonce portion of the generation
transaction is incremented, which changes the Merkle
root.
14. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Bitcoin theory.
Simplified
Merkle root
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
More details: https://5minuteblockchain.com/2019/05/20/blocks-in-bitcoin/
15. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP .NET CONFERENCE #1 IN UKRAINE KYIV 2019
Everything is clear.
Let’s start programming!
16. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP .NET CONFERENCE #1 IN UKRAINE KYIV 2019
But, let’s imaging the solution first…
19. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Where to start?
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
Start with Integration test for Happy path!
21. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Step 1: Basic solution
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
Outcome:
• Integration test in "unit test like" style
• we know basic interfaces, models, draft project structure
• we can "run" the solution!!!
• we can split work into at least 2 stream:
• protocol research to identify contracts and refine them -
IBitcoinClient
• continue work on architecture and design for mining - IMiner
23. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Step 2: Infrastructure
& Scaling prototype
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
Outcome:
• Established architecture
• Approach on how to address key problem - scalability
• Can run performance tests
• Not afraid to refactor
• Can split work into multiple streams
• Can validate refactored solution
24. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Next steps…
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
Refactoring goals:
• align implementation with standards
• write unit tests to address Sad/Bad paths
• Improving infrastructure
• Etc.
25. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Key takeaways
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
Serverless
• Quick infrastructure prototyping
• Infrastructure as a Code (IaaC)
Integration test:
• Focus on end result
• Solution scaffolding
• Quick solution to run
• Early demo to engage business
• Framework to develop in parallel by multiple teams with confidence
• Write unit tests for stable parts
27. Тема доклада
Тема доклада
Тема доклада
.NET LEVEL UP
Don’t know how to proceed – write tests!
.NET CONFERENCE #1 IN UKRAINE KYIV 2019
Thanks and have a green tests!