SlideShare a Scribd company logo
Indianapolis MuleSoft Meetup Group
Effective Unit Testing in MuleSoft
2
Organizer
Ikram Mohamed
Integration Associate
@OneAmerica
About the organizer:
 Working as Integration Associate at OneAmerica.
 Indianapolis MuleSoft Meetup Leader & Mentor.
 15+ Years of I.T Experience
 Certified MuleSoft Integration Developer and
Platform Architect.
Speaker
3
Josh Erney
MuleSoft Ambassador
About me
● MuleSoft Ambassador
● Developing/Architecting MuleSoft solutions ~5 years
● Typically approach software development from a financial & long-term maintainability
standpoint
○ “If you want to go fast, do it right”
4
About me
● MuleSoft Ambassador
● Developing/Architecting MuleSoft solutions ~5 years
● Typically approach software development from a financial & maintainability standpoint
○ “If you want to go fast, do it right”
● 2 Dogs - Eddie, Bennie
● Wrote the tutorial for the DataWeave Playground
● Wrote half of a book on DataWeave, once
5
Effective Unit Testing in MuleSoft
5 Steps
1. Understand the value of unit tests
2. Assert your code meets interface contracts
3. Write testable code
4. Remove the noise
5. Valuable tests first, code coverage second
7
Where did these steps come from
A lot of code reviews over the last year. What I found:
● Despite overall increases in code quality, tests were still lacking. Knowing how to write
maintainable source code doesn’t immediately translate to knowing how to write good tests.
● Developers were writing unit tests because they were required to, but the tests were weak.
● Code was passing automated build/deploy processes, but still had logic bugs when sent to QA
● Code coverage was high, but test quality was bad.
● After speaking with developers, I learned most didn’t understand the value of unit tests, and
therefore did not know how to create valuable tests.
● Ultimately: just having unit tests isn’t enough. Having poorly designed unit tests robs us of
productivity and increases maintenance costs.
8
Talk Objectives
I’d like you to walk away from this presentation able to:
● Describe why we write unit tests
● Identify high-value test cases within your code
● Understand how to write high-value tests
● Write testable code, refactor non-testable code into testable code
● Understand why we need to be thoughtful when using the test recorder
9
Keep the end goal in mind
1) Understand the Value of Unit Tests
Why do we create unit tests? What
makes them valuable?
The value of unit tests
● May increase code quality (maintenance costs ⬇️, dev velocity ⬆️)
● May enable developers to confidently refactor (maintenance costs ⬇️, dev velocity ⬆️)
● May enable developers to confidently add new features without introducing regressions
(maintenance costs ⬇️, dev velocity ⬆️)
● May reduce quantity of bugs (maintenance costs ⬇️, dev velocity ⬆️)
● May serve as a form of documentation (maintenance costs ⬇️, dev velocity ⬆️)
12
The value of unit tests
● May increase code quality (maintenance costs ⬇️, dev velocity ⬆️)
● May enable developers to confidently refactor (maintenance costs ⬇️, dev velocity ⬆️)
● May enable developers to confidently add new features without introducing regressions
(maintenance costs ⬇️, dev velocity ⬆️)
● May reduce quantity of bugs (maintenance costs ⬇️, dev velocity ⬆️)
● May serve as a form of documentation (maintenance costs ⬇️, dev velocity ⬆️)
Tests are for “future you”, and developers who may need to modify your code in the future.
13
Trivia 1
What is one of the benefits of writing valuable unit tests?
A. Makes your boss happy
B. May reduce maintenance costs
C. Better code coverage
D. May eliminate all bugs from your application
14
2) Assert Code Meets Interface Contracts
Assert code meets interface contracts
● Given inputs “x”, are calls to dependent APIs correct?
○ If synchronous API, is response correct (body and HTTP status code)?
● Test should fail if code does not meet interface expectations
○ i.e. “Payload is not null” is almost never enough
● Test of this type should never be viewed as optional
● Flows and subflows have interfaces, too!
16
Example: Asserting Code Meets Interface
Requirements
3) Write Testable Code
What makes code testable?
● “Testable” is a spectrum
○ You shouldn’t need to mock 10 different components
● Code that is thoughtfully organized into flows/sub-flows
○ Bias towards code organization that reflects how you would communicate about the code
■ “This flow gets data from system x, collects associated data from system y, then groups the data and sends
it to a queue”
● Values that need to be tested must be visible for testing
● Testable code is deterministic. Avoid using now() and random() within DW scripts. These
functions are non-deterministic.
○ We often need to use now(), how can we set up our source code and test to make this code
testable?
19
Trivia 2
What is a good indicator of testable software?
A. Good naming conventions
B. The software already has a lot of tests
C. The software tests provide great code coverage
D. Non-deterministic values are extracted into mockable variables
20
Example: Making our code testable
4) Eliminate the Noise
Eliminate the noise
23
● Noise is code or a test that cannot be linked back to a requirement or interface contract
● Noise could also be a test that doesn’t assert anything useful
● Noise ends up increasing maintenance costs instead of decreasing them
○ Noise creates confusion, “Why is this test making assertions about data that are not used by the
flow?”
● The MUnit Test Recorder can create a lot of noise, be thoughtful when using it! (more on this
later)
Demo - Munit Test Recorder
The Good
● Quickly create test cases
● Probably great code coverage if you
record every flow
Thoughts about the Test Recorder
25
The Bad
● Easier to create noise (e.g. forgetting not to mock
unnecessary attributes, mocking payloads with
100s of records)
● Poor file naming for things like mock payloads
● Cannot mock and spy the same component
● Mock data is always in application/dataweave
format
● File generation clutters src/test/resources
5) Valuable Tests First, Code Coverage
Second
Valuable Tests First, Code Coverage Second
● Code coverage can be a misleading metric for software quality
● Write your high-value tests first, check if code coverage criteria is met, then add more if
necessary
● Code reviews should be exposing weak tests
○ Helps mitigate developers aiming for code coverage instead of high-value tests
27
Other tips
28
● Unit tests should not be dependent on use of the network or file system
● More complex code should probably have more robust tests
● Tests should function as a form of documentation. Expected inputs to flows & dependent
systems, as well as expected outputs
● Test all paths. Generally flows with choice routers require 1 test per possible path. This
includes exceptions.
● Testing DataWeave code: Often times it’s not necessary, your interface tests should expose
bugs in transformation logic. DataWeave is an implementation detail.
● Never mock on doc:id alone, always include at least the doc:name
● Never trust a test that you haven’t seen fail
Trivia 3
When writing unit tests, why should you focus on writing valuable tests first, and code coverage
second?
A. Without valuable tests, code coverage is meaningless
B. Code coverage isn’t that important
C. Valuable tests are difficult to write, so we should approach them with a fresh mind
D. An authority figure said so in an online presentation
29
Example: MUnit Test Recorder
Questions?

More Related Content

What's hot

MuleSoft MUnit Test Recorder Meetup
MuleSoft MUnit Test Recorder MeetupMuleSoft MUnit Test Recorder Meetup
MuleSoft MUnit Test Recorder Meetup
Angel Alberici
 
Batch Processing with Mule 4
Batch Processing with Mule 4Batch Processing with Mule 4
Batch Processing with Mule 4
NeerajKumar1965
 
Indore MuleSoft Meetup #4 : Demystifying Error Handling & Snowflake Integration
Indore MuleSoft Meetup #4 : Demystifying Error Handling & Snowflake IntegrationIndore MuleSoft Meetup #4 : Demystifying Error Handling & Snowflake Integration
Indore MuleSoft Meetup #4 : Demystifying Error Handling & Snowflake Integration
IndoreMulesoftMeetup
 
Bhopal mule soft_meetup#2_18sept2021_cloudhubdr_strategy_bestpractices
Bhopal mule soft_meetup#2_18sept2021_cloudhubdr_strategy_bestpracticesBhopal mule soft_meetup#2_18sept2021_cloudhubdr_strategy_bestpractices
Bhopal mule soft_meetup#2_18sept2021_cloudhubdr_strategy_bestpractices
Preetam Deshmukh
 
Demystifying the use of circuit breakers with MuleSoft
Demystifying the use of circuit breakers with MuleSoftDemystifying the use of circuit breakers with MuleSoft
Demystifying the use of circuit breakers with MuleSoft
Sandeep Deshmukh
 
MuleSoft Meetup Bangalore - March 6 2021
MuleSoft Meetup Bangalore - March 6 2021MuleSoft Meetup Bangalore - March 6 2021
MuleSoft Meetup Bangalore - March 6 2021
Nagaraju K R
 
9th Manila MuleSoft Meetup July 2021
9th Manila MuleSoft Meetup July 20219th Manila MuleSoft Meetup July 2021
9th Manila MuleSoft Meetup July 2021
Ryan Anthony Andal
 
Ahmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalerts
Ahmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalertsAhmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalerts
Ahmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalerts
Shekh Muenuddeen
 
Bhopal mule soft_meetup_17july2021_azuredevopsintegration_mulesoft
Bhopal mule soft_meetup_17july2021_azuredevopsintegration_mulesoftBhopal mule soft_meetup_17july2021_azuredevopsintegration_mulesoft
Bhopal mule soft_meetup_17july2021_azuredevopsintegration_mulesoft
AnkitaJaggi1
 
Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...
Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...
Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...
OdessaJS Conf
 
Testing strategies and best practices using MUnit
Testing strategies and best practices using MUnitTesting strategies and best practices using MUnit
Testing strategies and best practices using MUnit
Jimmy Attia
 
MuleSoft meetup__houston #13
MuleSoft meetup__houston #13MuleSoft meetup__houston #13
MuleSoft meetup__houston #13
Jim Andrews
 
MuleSoft Kochi Meetup #5– Handling Mule Exceptions
MuleSoft Kochi Meetup #5– Handling Mule ExceptionsMuleSoft Kochi Meetup #5– Handling Mule Exceptions
MuleSoft Kochi Meetup #5– Handling Mule Exceptions
sumitahuja94
 
Overview on Anypoint Platform APIs and Anypoint Studio Tips and Tricks
Overview on Anypoint Platform APIs and Anypoint Studio Tips and TricksOverview on Anypoint Platform APIs and Anypoint Studio Tips and Tricks
Overview on Anypoint Platform APIs and Anypoint Studio Tips and Tricks
MergeStack
 
NYC MuleSoft Meetup 2019 Q2- MuleSoft for Mobile Applications
NYC MuleSoft Meetup 2019 Q2- MuleSoft for Mobile ApplicationsNYC MuleSoft Meetup 2019 Q2- MuleSoft for Mobile Applications
NYC MuleSoft Meetup 2019 Q2- MuleSoft for Mobile Applications
Gean Martinez
 
mulesoft meetup @ bangalore
mulesoft meetup @ bangaloremulesoft meetup @ bangalore
mulesoft meetup @ bangalore
D.Rajesh Kumar
 
Mule soft meetup_-_finland_july_11th__2020
Mule soft meetup_-_finland_july_11th__2020Mule soft meetup_-_finland_july_11th__2020
Mule soft meetup_-_finland_july_11th__2020
D.Rajesh Kumar
 
MuleSoft Surat Virtual Meetup#34 - OAS 3.0 full API lifecycle support with An...
MuleSoft Surat Virtual Meetup#34 - OAS 3.0 full API lifecycle support with An...MuleSoft Surat Virtual Meetup#34 - OAS 3.0 full API lifecycle support with An...
MuleSoft Surat Virtual Meetup#34 - OAS 3.0 full API lifecycle support with An...
Jitendra Bafna
 
Virtual meetup - Exploring the Runtime Fabric deployment model
Virtual meetup - Exploring the Runtime Fabric deployment modelVirtual meetup - Exploring the Runtime Fabric deployment model
Virtual meetup - Exploring the Runtime Fabric deployment model
Jimmy Attia
 
Mulesoft KL Meetup 2
Mulesoft KL Meetup 2Mulesoft KL Meetup 2
Mulesoft KL Meetup 2
NitushreeJena
 

What's hot (20)

MuleSoft MUnit Test Recorder Meetup
MuleSoft MUnit Test Recorder MeetupMuleSoft MUnit Test Recorder Meetup
MuleSoft MUnit Test Recorder Meetup
 
Batch Processing with Mule 4
Batch Processing with Mule 4Batch Processing with Mule 4
Batch Processing with Mule 4
 
Indore MuleSoft Meetup #4 : Demystifying Error Handling & Snowflake Integration
Indore MuleSoft Meetup #4 : Demystifying Error Handling & Snowflake IntegrationIndore MuleSoft Meetup #4 : Demystifying Error Handling & Snowflake Integration
Indore MuleSoft Meetup #4 : Demystifying Error Handling & Snowflake Integration
 
Bhopal mule soft_meetup#2_18sept2021_cloudhubdr_strategy_bestpractices
Bhopal mule soft_meetup#2_18sept2021_cloudhubdr_strategy_bestpracticesBhopal mule soft_meetup#2_18sept2021_cloudhubdr_strategy_bestpractices
Bhopal mule soft_meetup#2_18sept2021_cloudhubdr_strategy_bestpractices
 
Demystifying the use of circuit breakers with MuleSoft
Demystifying the use of circuit breakers with MuleSoftDemystifying the use of circuit breakers with MuleSoft
Demystifying the use of circuit breakers with MuleSoft
 
MuleSoft Meetup Bangalore - March 6 2021
MuleSoft Meetup Bangalore - March 6 2021MuleSoft Meetup Bangalore - March 6 2021
MuleSoft Meetup Bangalore - March 6 2021
 
9th Manila MuleSoft Meetup July 2021
9th Manila MuleSoft Meetup July 20219th Manila MuleSoft Meetup July 2021
9th Manila MuleSoft Meetup July 2021
 
Ahmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalerts
Ahmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalertsAhmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalerts
Ahmadabad mule soft_meetup_11_october_2020_errorhanlingandmonitoringalerts
 
Bhopal mule soft_meetup_17july2021_azuredevopsintegration_mulesoft
Bhopal mule soft_meetup_17july2021_azuredevopsintegration_mulesoftBhopal mule soft_meetup_17july2021_azuredevopsintegration_mulesoft
Bhopal mule soft_meetup_17july2021_azuredevopsintegration_mulesoft
 
Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...
Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...
Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...
 
Testing strategies and best practices using MUnit
Testing strategies and best practices using MUnitTesting strategies and best practices using MUnit
Testing strategies and best practices using MUnit
 
MuleSoft meetup__houston #13
MuleSoft meetup__houston #13MuleSoft meetup__houston #13
MuleSoft meetup__houston #13
 
MuleSoft Kochi Meetup #5– Handling Mule Exceptions
MuleSoft Kochi Meetup #5– Handling Mule ExceptionsMuleSoft Kochi Meetup #5– Handling Mule Exceptions
MuleSoft Kochi Meetup #5– Handling Mule Exceptions
 
Overview on Anypoint Platform APIs and Anypoint Studio Tips and Tricks
Overview on Anypoint Platform APIs and Anypoint Studio Tips and TricksOverview on Anypoint Platform APIs and Anypoint Studio Tips and Tricks
Overview on Anypoint Platform APIs and Anypoint Studio Tips and Tricks
 
NYC MuleSoft Meetup 2019 Q2- MuleSoft for Mobile Applications
NYC MuleSoft Meetup 2019 Q2- MuleSoft for Mobile ApplicationsNYC MuleSoft Meetup 2019 Q2- MuleSoft for Mobile Applications
NYC MuleSoft Meetup 2019 Q2- MuleSoft for Mobile Applications
 
mulesoft meetup @ bangalore
mulesoft meetup @ bangaloremulesoft meetup @ bangalore
mulesoft meetup @ bangalore
 
Mule soft meetup_-_finland_july_11th__2020
Mule soft meetup_-_finland_july_11th__2020Mule soft meetup_-_finland_july_11th__2020
Mule soft meetup_-_finland_july_11th__2020
 
MuleSoft Surat Virtual Meetup#34 - OAS 3.0 full API lifecycle support with An...
MuleSoft Surat Virtual Meetup#34 - OAS 3.0 full API lifecycle support with An...MuleSoft Surat Virtual Meetup#34 - OAS 3.0 full API lifecycle support with An...
MuleSoft Surat Virtual Meetup#34 - OAS 3.0 full API lifecycle support with An...
 
Virtual meetup - Exploring the Runtime Fabric deployment model
Virtual meetup - Exploring the Runtime Fabric deployment modelVirtual meetup - Exploring the Runtime Fabric deployment model
Virtual meetup - Exploring the Runtime Fabric deployment model
 
Mulesoft KL Meetup 2
Mulesoft KL Meetup 2Mulesoft KL Meetup 2
Mulesoft KL Meetup 2
 

Similar to Indy meetup#7 effective unit-testing-mule

Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
wesovi
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
Brett Child
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)
Abhijeet Vaikar
 
Android Test Driven Development & Android Unit Testing
Android Test Driven Development & Android Unit TestingAndroid Test Driven Development & Android Unit Testing
Android Test Driven Development & Android Unit Testing
mahmoud ramadan
 
What is Unit Testing
What is Unit TestingWhat is Unit Testing
What is Unit Testing
Sadaaki Emura
 
PMI-ACP Lesson 06 Quality
PMI-ACP Lesson 06 QualityPMI-ACP Lesson 06 Quality
PMI-ACP Lesson 06 Quality
Thanh Nguyen
 
Test driven development
Test driven developmentTest driven development
Test driven development
Harry Potter
 
Test driven development
Test driven developmentTest driven development
Test driven development
Luis Goldster
 
Test driven development
Test driven developmentTest driven development
Test driven development
Tony Nguyen
 
Test driven development
Test driven developmentTest driven development
Test driven development
Young Alista
 
Test driven development
Test driven developmentTest driven development
Test driven development
James Wong
 
Test driven development
Test driven developmentTest driven development
Test driven development
Fraboni Ec
 
Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening
Maven Logix
 
Software Defect Prevention via Continuous Inspection
Software Defect Prevention via Continuous InspectionSoftware Defect Prevention via Continuous Inspection
Software Defect Prevention via Continuous Inspection
Josh Gough
 
Technical debt management strategies
Technical debt management strategiesTechnical debt management strategies
Technical debt management strategies
Raquel Pau
 
Best Practices in Software Development
Best Practices in Software DevelopmentBest Practices in Software Development
Best Practices in Software Development
André Pitombeira
 
PHPUnit with Magento
PHPUnit with MagentoPHPUnit with Magento
PHPUnit with Magento
Tu Hoang
 
Test driven development
Test driven developmentTest driven development
Test driven development
Sharafat Ibn Mollah Mosharraf
 
Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
Behavior Driven Development—A Guide to Agile Practices by Josh EastmanBehavior Driven Development—A Guide to Agile Practices by Josh Eastman
Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
QA or the Highway
 
Agile Testing - What is it?
Agile Testing - What is it?Agile Testing - What is it?
Agile Testing - What is it?
Intelliware Development Inc.
 

Similar to Indy meetup#7 effective unit-testing-mule (20)

Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)
 
Android Test Driven Development & Android Unit Testing
Android Test Driven Development & Android Unit TestingAndroid Test Driven Development & Android Unit Testing
Android Test Driven Development & Android Unit Testing
 
What is Unit Testing
What is Unit TestingWhat is Unit Testing
What is Unit Testing
 
PMI-ACP Lesson 06 Quality
PMI-ACP Lesson 06 QualityPMI-ACP Lesson 06 Quality
PMI-ACP Lesson 06 Quality
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening
 
Software Defect Prevention via Continuous Inspection
Software Defect Prevention via Continuous InspectionSoftware Defect Prevention via Continuous Inspection
Software Defect Prevention via Continuous Inspection
 
Technical debt management strategies
Technical debt management strategiesTechnical debt management strategies
Technical debt management strategies
 
Best Practices in Software Development
Best Practices in Software DevelopmentBest Practices in Software Development
Best Practices in Software Development
 
PHPUnit with Magento
PHPUnit with MagentoPHPUnit with Magento
PHPUnit with Magento
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
Behavior Driven Development—A Guide to Agile Practices by Josh EastmanBehavior Driven Development—A Guide to Agile Practices by Josh Eastman
Behavior Driven Development—A Guide to Agile Practices by Josh Eastman
 
Agile Testing - What is it?
Agile Testing - What is it?Agile Testing - What is it?
Agile Testing - What is it?
 

More from ikram_ahamed

Indy_MuleSoft_Meetup_Sept_30 2 (1).pptx
Indy_MuleSoft_Meetup_Sept_30 2 (1).pptxIndy_MuleSoft_Meetup_Sept_30 2 (1).pptx
Indy_MuleSoft_Meetup_Sept_30 2 (1).pptx
ikram_ahamed
 
Indianapolis_meetup_April-1st-2022.pptx
Indianapolis_meetup_April-1st-2022.pptxIndianapolis_meetup_April-1st-2022.pptx
Indianapolis_meetup_April-1st-2022.pptx
ikram_ahamed
 
Indianapolis mulesoft meetup_sep_11_2021
Indianapolis mulesoft meetup_sep_11_2021Indianapolis mulesoft meetup_sep_11_2021
Indianapolis mulesoft meetup_sep_11_2021
ikram_ahamed
 
Indianapolis mule soft_meetup_12_june_2021
Indianapolis mule soft_meetup_12_june_2021Indianapolis mule soft_meetup_12_june_2021
Indianapolis mule soft_meetup_12_june_2021
ikram_ahamed
 
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
ikram_ahamed
 
Indianapolis mule soft_meetup_30_jan_2021 (1)
Indianapolis mule soft_meetup_30_jan_2021 (1)Indianapolis mule soft_meetup_30_jan_2021 (1)
Indianapolis mule soft_meetup_30_jan_2021 (1)
ikram_ahamed
 

More from ikram_ahamed (6)

Indy_MuleSoft_Meetup_Sept_30 2 (1).pptx
Indy_MuleSoft_Meetup_Sept_30 2 (1).pptxIndy_MuleSoft_Meetup_Sept_30 2 (1).pptx
Indy_MuleSoft_Meetup_Sept_30 2 (1).pptx
 
Indianapolis_meetup_April-1st-2022.pptx
Indianapolis_meetup_April-1st-2022.pptxIndianapolis_meetup_April-1st-2022.pptx
Indianapolis_meetup_April-1st-2022.pptx
 
Indianapolis mulesoft meetup_sep_11_2021
Indianapolis mulesoft meetup_sep_11_2021Indianapolis mulesoft meetup_sep_11_2021
Indianapolis mulesoft meetup_sep_11_2021
 
Indianapolis mule soft_meetup_12_june_2021
Indianapolis mule soft_meetup_12_june_2021Indianapolis mule soft_meetup_12_june_2021
Indianapolis mule soft_meetup_12_june_2021
 
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
Indianapolis mule soft_meetup_14_apr_2021-Review a complex Dataweave Transfor...
 
Indianapolis mule soft_meetup_30_jan_2021 (1)
Indianapolis mule soft_meetup_30_jan_2021 (1)Indianapolis mule soft_meetup_30_jan_2021 (1)
Indianapolis mule soft_meetup_30_jan_2021 (1)
 

Recently uploaded

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Hivelance Technology
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
Peter Caitens
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 

Recently uploaded (20)

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 

Indy meetup#7 effective unit-testing-mule

  • 1. Indianapolis MuleSoft Meetup Group Effective Unit Testing in MuleSoft
  • 2. 2 Organizer Ikram Mohamed Integration Associate @OneAmerica About the organizer:  Working as Integration Associate at OneAmerica.  Indianapolis MuleSoft Meetup Leader & Mentor.  15+ Years of I.T Experience  Certified MuleSoft Integration Developer and Platform Architect.
  • 4. About me ● MuleSoft Ambassador ● Developing/Architecting MuleSoft solutions ~5 years ● Typically approach software development from a financial & long-term maintainability standpoint ○ “If you want to go fast, do it right” 4
  • 5. About me ● MuleSoft Ambassador ● Developing/Architecting MuleSoft solutions ~5 years ● Typically approach software development from a financial & maintainability standpoint ○ “If you want to go fast, do it right” ● 2 Dogs - Eddie, Bennie ● Wrote the tutorial for the DataWeave Playground ● Wrote half of a book on DataWeave, once 5
  • 7. 5 Steps 1. Understand the value of unit tests 2. Assert your code meets interface contracts 3. Write testable code 4. Remove the noise 5. Valuable tests first, code coverage second 7
  • 8. Where did these steps come from A lot of code reviews over the last year. What I found: ● Despite overall increases in code quality, tests were still lacking. Knowing how to write maintainable source code doesn’t immediately translate to knowing how to write good tests. ● Developers were writing unit tests because they were required to, but the tests were weak. ● Code was passing automated build/deploy processes, but still had logic bugs when sent to QA ● Code coverage was high, but test quality was bad. ● After speaking with developers, I learned most didn’t understand the value of unit tests, and therefore did not know how to create valuable tests. ● Ultimately: just having unit tests isn’t enough. Having poorly designed unit tests robs us of productivity and increases maintenance costs. 8
  • 9. Talk Objectives I’d like you to walk away from this presentation able to: ● Describe why we write unit tests ● Identify high-value test cases within your code ● Understand how to write high-value tests ● Write testable code, refactor non-testable code into testable code ● Understand why we need to be thoughtful when using the test recorder 9
  • 10. Keep the end goal in mind 1) Understand the Value of Unit Tests
  • 11. Why do we create unit tests? What makes them valuable?
  • 12. The value of unit tests ● May increase code quality (maintenance costs ⬇️, dev velocity ⬆️) ● May enable developers to confidently refactor (maintenance costs ⬇️, dev velocity ⬆️) ● May enable developers to confidently add new features without introducing regressions (maintenance costs ⬇️, dev velocity ⬆️) ● May reduce quantity of bugs (maintenance costs ⬇️, dev velocity ⬆️) ● May serve as a form of documentation (maintenance costs ⬇️, dev velocity ⬆️) 12
  • 13. The value of unit tests ● May increase code quality (maintenance costs ⬇️, dev velocity ⬆️) ● May enable developers to confidently refactor (maintenance costs ⬇️, dev velocity ⬆️) ● May enable developers to confidently add new features without introducing regressions (maintenance costs ⬇️, dev velocity ⬆️) ● May reduce quantity of bugs (maintenance costs ⬇️, dev velocity ⬆️) ● May serve as a form of documentation (maintenance costs ⬇️, dev velocity ⬆️) Tests are for “future you”, and developers who may need to modify your code in the future. 13
  • 14. Trivia 1 What is one of the benefits of writing valuable unit tests? A. Makes your boss happy B. May reduce maintenance costs C. Better code coverage D. May eliminate all bugs from your application 14
  • 15. 2) Assert Code Meets Interface Contracts
  • 16. Assert code meets interface contracts ● Given inputs “x”, are calls to dependent APIs correct? ○ If synchronous API, is response correct (body and HTTP status code)? ● Test should fail if code does not meet interface expectations ○ i.e. “Payload is not null” is almost never enough ● Test of this type should never be viewed as optional ● Flows and subflows have interfaces, too! 16
  • 17. Example: Asserting Code Meets Interface Requirements
  • 19. What makes code testable? ● “Testable” is a spectrum ○ You shouldn’t need to mock 10 different components ● Code that is thoughtfully organized into flows/sub-flows ○ Bias towards code organization that reflects how you would communicate about the code ■ “This flow gets data from system x, collects associated data from system y, then groups the data and sends it to a queue” ● Values that need to be tested must be visible for testing ● Testable code is deterministic. Avoid using now() and random() within DW scripts. These functions are non-deterministic. ○ We often need to use now(), how can we set up our source code and test to make this code testable? 19
  • 20. Trivia 2 What is a good indicator of testable software? A. Good naming conventions B. The software already has a lot of tests C. The software tests provide great code coverage D. Non-deterministic values are extracted into mockable variables 20
  • 21. Example: Making our code testable
  • 23. Eliminate the noise 23 ● Noise is code or a test that cannot be linked back to a requirement or interface contract ● Noise could also be a test that doesn’t assert anything useful ● Noise ends up increasing maintenance costs instead of decreasing them ○ Noise creates confusion, “Why is this test making assertions about data that are not used by the flow?” ● The MUnit Test Recorder can create a lot of noise, be thoughtful when using it! (more on this later)
  • 24. Demo - Munit Test Recorder
  • 25. The Good ● Quickly create test cases ● Probably great code coverage if you record every flow Thoughts about the Test Recorder 25 The Bad ● Easier to create noise (e.g. forgetting not to mock unnecessary attributes, mocking payloads with 100s of records) ● Poor file naming for things like mock payloads ● Cannot mock and spy the same component ● Mock data is always in application/dataweave format ● File generation clutters src/test/resources
  • 26. 5) Valuable Tests First, Code Coverage Second
  • 27. Valuable Tests First, Code Coverage Second ● Code coverage can be a misleading metric for software quality ● Write your high-value tests first, check if code coverage criteria is met, then add more if necessary ● Code reviews should be exposing weak tests ○ Helps mitigate developers aiming for code coverage instead of high-value tests 27
  • 28. Other tips 28 ● Unit tests should not be dependent on use of the network or file system ● More complex code should probably have more robust tests ● Tests should function as a form of documentation. Expected inputs to flows & dependent systems, as well as expected outputs ● Test all paths. Generally flows with choice routers require 1 test per possible path. This includes exceptions. ● Testing DataWeave code: Often times it’s not necessary, your interface tests should expose bugs in transformation logic. DataWeave is an implementation detail. ● Never mock on doc:id alone, always include at least the doc:name ● Never trust a test that you haven’t seen fail
  • 29. Trivia 3 When writing unit tests, why should you focus on writing valuable tests first, and code coverage second? A. Without valuable tests, code coverage is meaningless B. Code coverage isn’t that important C. Valuable tests are difficult to write, so we should approach them with a fresh mind D. An authority figure said so in an online presentation 29