SlideShare a Scribd company logo
1 of 31
Download to read offline
Hyperpragmatic pure FP testing with distage-testkit
1/31
Hyperpragmatic pure FP testing
with
distage-testkit
Functional Scala 2019
Septimal Mind Ltd
team@7mind.io
1 / 31
Hyperpragmatic pure FP testing with distage-testkit
Tests and Test Taxonomies 2/31
Not all the tests are equal
Tests are important. We know that.
Tests are the simplest way to define and verify important contracts.
And contracts are crucial for project maintainability and viability.
We write tests. A lot of.
But
. . .
some tests prove themselves useful and some do not.
2 / 31
Hyperpragmatic pure FP testing with distage-testkit
Tests and Test Taxonomies 3/31
Not all the tests are equal
Which tests are good and which are bad?
3 / 31
Hyperpragmatic pure FP testing with distage-testkit
Tests and Test Taxonomies 4/31
Bad test criterias
Bad tests are:
◮ Slow,
◮ Unstable: they fail randomly,
◮ Nonviable: they don’t survive refactorings,
◮ Demanding: they require complex preconditions to be met: external services up and
running, fixtures loaded, etc, etc,
◮ Incomprehensible: they signal about a problem but don’t help us to localize the
cause.
4 / 31
Hyperpragmatic pure FP testing with distage-testkit
Tests and Test Taxonomies 5/31
We spend more resources to write and
maintain bad tests
than the value they bring us.
5 / 31
Hyperpragmatic pure FP testing with distage-testkit
Tests and Test Taxonomies 6/31
How may we make our tests better?
6 / 31
Hyperpragmatic pure FP testing with distage-testkit
Tests and Test Taxonomies 7/31
Let’s ditch Unit/Functional/Integration trinity. . .
. . . and introduce some new terminology
7 / 31
Hyperpragmatic pure FP testing with distage-testkit
Tests and Test Taxonomies 8/31
Test Taxonomy: Encapsulation Axis
Let’s say that every test falls under one of the following categories:
1. Blackbox tests check just interfaces not knowing anything about implementations
behind them,
2. Whitebox tests may know about implementations and check them directly, sometimes
even breaking into some internal state to verify if it conforms to test expectations.
8 / 31
Hyperpragmatic pure FP testing with distage-testkit
Tests and Test Taxonomies 9/31
Test Taxonomy: Isolation Axis
Let’s say that every test falls under one of the following categories:
◮ Atomic tests check just one “unsplittable” software component,
◮ Group tests check multiple software components,
◮ Communication tests communicate with outer world (databases, API providers, etc,
etc).
9 / 31
Hyperpragmatic pure FP testing with distage-testkit
Tests and Test Taxonomies 10/31
You may extend and modify this Test Taxonomy as it would be convenient for you.
More about test taxonomies:
https://blog.7mind.io/constructive-test-taxonomy.html 10 / 31
Hyperpragmatic pure FP testing with distage-testkit
Tests and Test Taxonomies 11/31
Test Taxonomy: Why So?
According to our experience the best tests are
Blackbox tests with Atomic or Group Isolation Level.
This makes sense: such tests are fast and refactoring-resilient.
11 / 31
Hyperpragmatic pure FP testing with distage-testkit
Tests and Test Taxonomies 12/31
Communication tests
But in real projects most of the tests fall under Communication category (“Integration”
tests).
Why?
1. Engineers want to test The Whole Thing,
2. It’s hard to separate components,
3. etc, etc. . .
12 / 31
Hyperpragmatic pure FP testing with distage-testkit
Tests and Test Taxonomies 13/31
Communication tests can be more useful
We may replace integration components with Dummies1.
This way we may turn
Communication tests
into
Group or Atomic2
1
people also call them “Fakes”, “in-memory implementations” or “Mocks”
2
this statement is valid for Blackbox tests only
13 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 14/31
Dual Test Tactic
The same test scenario executed with both Production and Dummy implementations of
integration components is beneficial:
1. We can test business logic quickly, without any interference,
2. We still able to verify business logic behaviour with “real” integrations,
3. Dual Test Tactic enforces us to follow LSP and design better.
Refactorings are crucial for long-term health of the project.
Blackbox tests enable refactorings.
Dual Test Tactic drastically reduces the price of refactorings.
14 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 15/31
Dual Test Tactic: ideas
1. Ignore Communication tests in case their dependencies are unsatisfied (service
unavailable), don’t fail,
2. Avoid automatic “Mocks”, they prevent encapsulation,
3. Never run heavy dependencies in-process
◮ don’t bring whole Kafka or Cassandra into the classpath. PLEASE
15 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 16/31
Dual Test Tactic: The Main Issue
It’s easy to setup test dependencies while working with Dummies
But you have to do things differently for Production dependencies.
We have to take care of:
1. Resource acquisition and Cleanups,
2. Speed,
3. Memoization and resource reuse,
4. Interference,
5. . . .
16 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 17/31
Dual Test Tactic: dummy repositories testcase
make[UserRepo]
make[UserService]
make[AccountsRepo]
make[AccountsService]
run[MyTestCase] run[AnotherTestCase]
17 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 18/31
Dual Test Tactic: production repositories testcase
Setup
Execute
Cleanup
probe database port
make[DbDriver]
setup users table setup accounts table
make[UserRepo] make[AccountsRepo]
remove users table
close driver
remove accounts table
make[UserService] make[AccountsService]
run[MyTestCase]run[AnotherTestCase]
1. Order
2. How to avoid unneccessary job?
2.1 Memoize resources?..
2.2 In a singleton?..
2.3 When we close resources?..
2.4 On JVM shutdown?.. Oops, SBT. . .
2.5 Disambiguation (same class, different
parameters)?..
3. Resource deallocation
3.1 . . . even after a failure
3.2 Order!
4. Other integrations, e.g. run Dockers
4.1 . . . and await until they open ports
4.2 . . . and stop them after the tests
5. Configs 18 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 19/31
Dual Test Tactic: Real testcase steps
◮ Integration points stack together
◮ . . . and make the problem notably hard
◮ Manual wiring is hard to maintain
◮ . . . and suffers from combinatoric explosion of possible code paths
◮ Cake pattern doesn’t make much difference
◮ Conventional DI frameworks fail
It’s hard to setup variable contexts.
19 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 20/31
Dual Test Tactic
may be very pricy under usual circumstances.
20 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 21/31
Can we make it cheap?
21 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 22/31
Yes.
22 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 23/31
The Goal
We want to write code like this and never care about setting things up:
1 class JustATest[F[+_, +_]] {
2 "service" must {
3 "do something" in {
4 (users: UserService[F], accounts: AccountingService[F]) =>
5 for {
6 user <- users.create()
7 balance <- accounts.getBalance(user)
8 } yield {
9 assert(balance == 0)
10 }
11 }
12 }
13 }
14
15 object JustATestZioProd extends JustATest[zio.IO] with Prod
16 object JustATestZioDummy extends JustATest[zio.IO] with Dummy 23 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 24/31
dist✪ge
is a Dependency Injection mechanism for Scala
But it lacks negative traits of a typical DI thingy. . .
. . . and has many unique properties.
. . . and it’s blazing fast.
You may call it a module system for Scala. . .
. . . with automatic garbage-collecting solver
24 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 25/31
distage
1. Supports FP, wires Resources, Effects, ZIO Environments. . .
2. transparent and predictable
◮ first plan then do
◮ test the outcome without effect execution!
◮ compile-time checks and tests
3. no scala-reflect nor Java reflection1,
◮ ScalaJS support is coming
4. is non-invasive.
◮ You can add it to your project keeping business logic intact. . .
◮ . . . and remove it.
5. is not an ad-hoc thing, it has strong theory behind.
1
Since version 0.10.0, see https://blog.7mind.io/lightweight-reflection.html
25 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 26/31
Docker support in distage
While we develop and test we may need our integrations up and running. . .
. . . We have docker-compose for that. . .
But manual rituals are annoying and Compose is imperfect
(wait until service opens port? Hah)
Container orchestration is not easy.
But. . .
We made a distage extension allowing to get rid of Compose in most of the cases.
It can run test containers, reuse and shutdown them.
And it can await until the service is ready.
26 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 27/31
Let’s look at a real example. . .
Source code: https://github.com/7mind/distage-example
27 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 28/31
distage performs optimal ahead of time planning.
It doesn’t do any unnecessary job.
28 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 29/31
One More Thing: Roles
distage allow you to fuse microservices into “flexible monoliths”.
We may:
1. Develop services (Roles) separately, even in a multirepo,
2. Build a single Docker image with multiple Roles in it,
3. Run several Roles within one process
◮ We define roles we want to start as commandline parameters
4. ⇒ higher computation density, savings on infrastructure,
5. ⇒ substantial development simplification
◮ full environment can be started on a low-end machine
◮ with just one command
29 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 30/31
distage-framework is the most productive way to write
maintainable pure functional applications with ZIO.
(And any other monad)
distage-testkit is the best way to make your tests performant and reliable.
distage is adopted by several different companies and
tested by two years of production usage.
30 / 31
Hyperpragmatic pure FP testing with distage-testkit
Dual Test Tactic 31/31
Thank you for your attention
distage website: https://izumi.7mind.io
Septimal Mind is an Irish software consultancy and R&D Company
We’re looking for clients, contributors, adopters and colleagues ;)
Contact: team@7mind.io
Github: https://github.com/7mind
Slides: https://github.com/7mind/slides
Follow us on Twitter
https://twitter.com/shirshovp
https://twitter.com/kai_nyasha
31 / 31

More Related Content

What's hot

Testing with JUnit 5 and Spring
Testing with JUnit 5 and SpringTesting with JUnit 5 and Spring
Testing with JUnit 5 and SpringVMware Tanzu
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFXHendrik Ebbers
 
Load Testing with k6 framework
Load Testing with k6 frameworkLoad Testing with k6 framework
Load Testing with k6 frameworkSvetlin Nakov
 
Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013Hazem Saleh
 
[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for AndroidHazem Saleh
 
Java 9 New Features
Java 9 New FeaturesJava 9 New Features
Java 9 New FeaturesAli BAKAN
 
How to setup unit testing in Android Studio
How to setup unit testing in Android StudioHow to setup unit testing in Android Studio
How to setup unit testing in Android Studiotobiaspreuss
 
Unit Test Android Without Going Bald
Unit Test Android Without Going BaldUnit Test Android Without Going Bald
Unit Test Android Without Going BaldDavid Carver
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in YiiIlPeach
 
Qtp interview questions and answers
Qtp interview questions and answersQtp interview questions and answers
Qtp interview questions and answersITeLearn
 
Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02rhemsolutions
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Appschrisb206 chrisb206
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit TestChiew Carol
 
Grails plugin development
Grails plugin developmentGrails plugin development
Grails plugin developmentMohd Farid
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Codescidept
 
Testing Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkTesting Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkDmytro Chyzhykov
 

What's hot (20)

Testing with JUnit 5 and Spring
Testing with JUnit 5 and SpringTesting with JUnit 5 and Spring
Testing with JUnit 5 and Spring
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
Load Testing with k6 framework
Load Testing with k6 frameworkLoad Testing with k6 framework
Load Testing with k6 framework
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013
 
[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android[AnDevCon 2016] Mutation Testing for Android
[AnDevCon 2016] Mutation Testing for Android
 
Java 9 New Features
Java 9 New FeaturesJava 9 New Features
Java 9 New Features
 
How to setup unit testing in Android Studio
How to setup unit testing in Android StudioHow to setup unit testing in Android Studio
How to setup unit testing in Android Studio
 
Unit Test Android Without Going Bald
Unit Test Android Without Going BaldUnit Test Android Without Going Bald
Unit Test Android Without Going Bald
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in Yii
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Qtp interview questions and answers
Qtp interview questions and answersQtp interview questions and answers
Qtp interview questions and answers
 
Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit Test
 
Agile Swift
Agile SwiftAgile Swift
Agile Swift
 
Grails plugin development
Grails plugin developmentGrails plugin development
Grails plugin development
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Testing Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkTesting Web Apps with Spring Framework
Testing Web Apps with Spring Framework
 

Similar to Hyperpragmatic pure FP testing with distage-testkit

A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)Thierry Gayet
 
Software Testing
Software TestingSoftware Testing
Software TestingAdroitLogic
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosFlutter Agency
 
Unit Testing Frameworks: A comparative study
Unit Testing Frameworks: A comparative studyUnit Testing Frameworks: A comparative study
Unit Testing Frameworks: A comparative studyIRJET Journal
 
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
 
Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Fwdays
 
Dot all 2019 | Testing with Craft | Giel Tettelar
Dot all 2019 | Testing with Craft | Giel TettelarDot all 2019 | Testing with Craft | Giel Tettelar
Dot all 2019 | Testing with Craft | Giel TettelarGiel Tettelaar
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 
Testing in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita GalkinTesting in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita GalkinSigma Software
 
Lessons learned on software testing automation
Lessons learned on software testing automationLessons learned on software testing automation
Lessons learned on software testing automationgaoliang641
 
Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...
Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...
Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...Applitools
 
Software Testing: Test Design and the Project Life Cycle
Software Testing: Test Design and the Project Life CycleSoftware Testing: Test Design and the Project Life Cycle
Software Testing: Test Design and the Project Life CycleDerek Callaway
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django ApplicationsGareth Rushgrove
 
Testing Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksTesting Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksŁukasz Morawski
 
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
 
Google mock training
Google mock trainingGoogle mock training
Google mock trainingThierry Gayet
 
Containerize your Blackbox tests
Containerize your Blackbox testsContainerize your Blackbox tests
Containerize your Blackbox testsKevin Beeman
 

Similar to Hyperpragmatic pure FP testing with distage-testkit (20)

A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
 
Automating the Quality
Automating the QualityAutomating the Quality
Automating the Quality
 
Unit Testing Frameworks: A comparative study
Unit Testing Frameworks: A comparative studyUnit Testing Frameworks: A comparative study
Unit Testing Frameworks: A comparative study
 
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...
 
Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"
 
Dot all 2019 | Testing with Craft | Giel Tettelar
Dot all 2019 | Testing with Craft | Giel TettelarDot all 2019 | Testing with Craft | Giel Tettelar
Dot all 2019 | Testing with Craft | Giel Tettelar
 
Combined Project
Combined ProjectCombined Project
Combined Project
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Testing in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita GalkinTesting in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita Galkin
 
Lessons learned on software testing automation
Lessons learned on software testing automationLessons learned on software testing automation
Lessons learned on software testing automation
 
Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...
Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...
Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...
 
Software Testing: Test Design and the Project Life Cycle
Software Testing: Test Design and the Project Life CycleSoftware Testing: Test Design and the Project Life Cycle
Software Testing: Test Design and the Project Life Cycle
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django Applications
 
Testing Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksTesting Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation Frameworks
 
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
 
Google mock training
Google mock trainingGoogle mock training
Google mock training
 
Containerize your Blackbox tests
Containerize your Blackbox testsContainerize your Blackbox tests
Containerize your Blackbox tests
 

Recently uploaded

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 

Recently uploaded (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 

Hyperpragmatic pure FP testing with distage-testkit

  • 1. Hyperpragmatic pure FP testing with distage-testkit 1/31 Hyperpragmatic pure FP testing with distage-testkit Functional Scala 2019 Septimal Mind Ltd team@7mind.io 1 / 31
  • 2. Hyperpragmatic pure FP testing with distage-testkit Tests and Test Taxonomies 2/31 Not all the tests are equal Tests are important. We know that. Tests are the simplest way to define and verify important contracts. And contracts are crucial for project maintainability and viability. We write tests. A lot of. But . . . some tests prove themselves useful and some do not. 2 / 31
  • 3. Hyperpragmatic pure FP testing with distage-testkit Tests and Test Taxonomies 3/31 Not all the tests are equal Which tests are good and which are bad? 3 / 31
  • 4. Hyperpragmatic pure FP testing with distage-testkit Tests and Test Taxonomies 4/31 Bad test criterias Bad tests are: ◮ Slow, ◮ Unstable: they fail randomly, ◮ Nonviable: they don’t survive refactorings, ◮ Demanding: they require complex preconditions to be met: external services up and running, fixtures loaded, etc, etc, ◮ Incomprehensible: they signal about a problem but don’t help us to localize the cause. 4 / 31
  • 5. Hyperpragmatic pure FP testing with distage-testkit Tests and Test Taxonomies 5/31 We spend more resources to write and maintain bad tests than the value they bring us. 5 / 31
  • 6. Hyperpragmatic pure FP testing with distage-testkit Tests and Test Taxonomies 6/31 How may we make our tests better? 6 / 31
  • 7. Hyperpragmatic pure FP testing with distage-testkit Tests and Test Taxonomies 7/31 Let’s ditch Unit/Functional/Integration trinity. . . . . . and introduce some new terminology 7 / 31
  • 8. Hyperpragmatic pure FP testing with distage-testkit Tests and Test Taxonomies 8/31 Test Taxonomy: Encapsulation Axis Let’s say that every test falls under one of the following categories: 1. Blackbox tests check just interfaces not knowing anything about implementations behind them, 2. Whitebox tests may know about implementations and check them directly, sometimes even breaking into some internal state to verify if it conforms to test expectations. 8 / 31
  • 9. Hyperpragmatic pure FP testing with distage-testkit Tests and Test Taxonomies 9/31 Test Taxonomy: Isolation Axis Let’s say that every test falls under one of the following categories: ◮ Atomic tests check just one “unsplittable” software component, ◮ Group tests check multiple software components, ◮ Communication tests communicate with outer world (databases, API providers, etc, etc). 9 / 31
  • 10. Hyperpragmatic pure FP testing with distage-testkit Tests and Test Taxonomies 10/31 You may extend and modify this Test Taxonomy as it would be convenient for you. More about test taxonomies: https://blog.7mind.io/constructive-test-taxonomy.html 10 / 31
  • 11. Hyperpragmatic pure FP testing with distage-testkit Tests and Test Taxonomies 11/31 Test Taxonomy: Why So? According to our experience the best tests are Blackbox tests with Atomic or Group Isolation Level. This makes sense: such tests are fast and refactoring-resilient. 11 / 31
  • 12. Hyperpragmatic pure FP testing with distage-testkit Tests and Test Taxonomies 12/31 Communication tests But in real projects most of the tests fall under Communication category (“Integration” tests). Why? 1. Engineers want to test The Whole Thing, 2. It’s hard to separate components, 3. etc, etc. . . 12 / 31
  • 13. Hyperpragmatic pure FP testing with distage-testkit Tests and Test Taxonomies 13/31 Communication tests can be more useful We may replace integration components with Dummies1. This way we may turn Communication tests into Group or Atomic2 1 people also call them “Fakes”, “in-memory implementations” or “Mocks” 2 this statement is valid for Blackbox tests only 13 / 31
  • 14. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 14/31 Dual Test Tactic The same test scenario executed with both Production and Dummy implementations of integration components is beneficial: 1. We can test business logic quickly, without any interference, 2. We still able to verify business logic behaviour with “real” integrations, 3. Dual Test Tactic enforces us to follow LSP and design better. Refactorings are crucial for long-term health of the project. Blackbox tests enable refactorings. Dual Test Tactic drastically reduces the price of refactorings. 14 / 31
  • 15. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 15/31 Dual Test Tactic: ideas 1. Ignore Communication tests in case their dependencies are unsatisfied (service unavailable), don’t fail, 2. Avoid automatic “Mocks”, they prevent encapsulation, 3. Never run heavy dependencies in-process ◮ don’t bring whole Kafka or Cassandra into the classpath. PLEASE 15 / 31
  • 16. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 16/31 Dual Test Tactic: The Main Issue It’s easy to setup test dependencies while working with Dummies But you have to do things differently for Production dependencies. We have to take care of: 1. Resource acquisition and Cleanups, 2. Speed, 3. Memoization and resource reuse, 4. Interference, 5. . . . 16 / 31
  • 17. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 17/31 Dual Test Tactic: dummy repositories testcase make[UserRepo] make[UserService] make[AccountsRepo] make[AccountsService] run[MyTestCase] run[AnotherTestCase] 17 / 31
  • 18. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 18/31 Dual Test Tactic: production repositories testcase Setup Execute Cleanup probe database port make[DbDriver] setup users table setup accounts table make[UserRepo] make[AccountsRepo] remove users table close driver remove accounts table make[UserService] make[AccountsService] run[MyTestCase]run[AnotherTestCase] 1. Order 2. How to avoid unneccessary job? 2.1 Memoize resources?.. 2.2 In a singleton?.. 2.3 When we close resources?.. 2.4 On JVM shutdown?.. Oops, SBT. . . 2.5 Disambiguation (same class, different parameters)?.. 3. Resource deallocation 3.1 . . . even after a failure 3.2 Order! 4. Other integrations, e.g. run Dockers 4.1 . . . and await until they open ports 4.2 . . . and stop them after the tests 5. Configs 18 / 31
  • 19. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 19/31 Dual Test Tactic: Real testcase steps ◮ Integration points stack together ◮ . . . and make the problem notably hard ◮ Manual wiring is hard to maintain ◮ . . . and suffers from combinatoric explosion of possible code paths ◮ Cake pattern doesn’t make much difference ◮ Conventional DI frameworks fail It’s hard to setup variable contexts. 19 / 31
  • 20. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 20/31 Dual Test Tactic may be very pricy under usual circumstances. 20 / 31
  • 21. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 21/31 Can we make it cheap? 21 / 31
  • 22. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 22/31 Yes. 22 / 31
  • 23. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 23/31 The Goal We want to write code like this and never care about setting things up: 1 class JustATest[F[+_, +_]] { 2 "service" must { 3 "do something" in { 4 (users: UserService[F], accounts: AccountingService[F]) => 5 for { 6 user <- users.create() 7 balance <- accounts.getBalance(user) 8 } yield { 9 assert(balance == 0) 10 } 11 } 12 } 13 } 14 15 object JustATestZioProd extends JustATest[zio.IO] with Prod 16 object JustATestZioDummy extends JustATest[zio.IO] with Dummy 23 / 31
  • 24. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 24/31 dist✪ge is a Dependency Injection mechanism for Scala But it lacks negative traits of a typical DI thingy. . . . . . and has many unique properties. . . . and it’s blazing fast. You may call it a module system for Scala. . . . . . with automatic garbage-collecting solver 24 / 31
  • 25. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 25/31 distage 1. Supports FP, wires Resources, Effects, ZIO Environments. . . 2. transparent and predictable ◮ first plan then do ◮ test the outcome without effect execution! ◮ compile-time checks and tests 3. no scala-reflect nor Java reflection1, ◮ ScalaJS support is coming 4. is non-invasive. ◮ You can add it to your project keeping business logic intact. . . ◮ . . . and remove it. 5. is not an ad-hoc thing, it has strong theory behind. 1 Since version 0.10.0, see https://blog.7mind.io/lightweight-reflection.html 25 / 31
  • 26. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 26/31 Docker support in distage While we develop and test we may need our integrations up and running. . . . . . We have docker-compose for that. . . But manual rituals are annoying and Compose is imperfect (wait until service opens port? Hah) Container orchestration is not easy. But. . . We made a distage extension allowing to get rid of Compose in most of the cases. It can run test containers, reuse and shutdown them. And it can await until the service is ready. 26 / 31
  • 27. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 27/31 Let’s look at a real example. . . Source code: https://github.com/7mind/distage-example 27 / 31
  • 28. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 28/31 distage performs optimal ahead of time planning. It doesn’t do any unnecessary job. 28 / 31
  • 29. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 29/31 One More Thing: Roles distage allow you to fuse microservices into “flexible monoliths”. We may: 1. Develop services (Roles) separately, even in a multirepo, 2. Build a single Docker image with multiple Roles in it, 3. Run several Roles within one process ◮ We define roles we want to start as commandline parameters 4. ⇒ higher computation density, savings on infrastructure, 5. ⇒ substantial development simplification ◮ full environment can be started on a low-end machine ◮ with just one command 29 / 31
  • 30. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 30/31 distage-framework is the most productive way to write maintainable pure functional applications with ZIO. (And any other monad) distage-testkit is the best way to make your tests performant and reliable. distage is adopted by several different companies and tested by two years of production usage. 30 / 31
  • 31. Hyperpragmatic pure FP testing with distage-testkit Dual Test Tactic 31/31 Thank you for your attention distage website: https://izumi.7mind.io Septimal Mind is an Irish software consultancy and R&D Company We’re looking for clients, contributors, adopters and colleagues ;) Contact: team@7mind.io Github: https://github.com/7mind Slides: https://github.com/7mind/slides Follow us on Twitter https://twitter.com/shirshovp https://twitter.com/kai_nyasha 31 / 31