SlideShare una empresa de Scribd logo
1 de 37
Descargar para leer sin conexión
An Introduction to TDD
Lawton Spelliscy
Overview
● The benefits and shortcomings of TDD
● The tools of the trade
● Testing with JS and React
TDD 101
● Write Tests prior to
implementation
TDD 102
● Red, Green, Refactor
Benefits of Testing
● Tests run fast
● Early step in automated
deployment
● Help avoid introducing bugs in
greater code base
● Live documentation
Benefits of TDD
● Clear, Concise Code
● Minimize context switching
● Catches bugs early
● Better live documentation
Frustrations
● Feels unnatural
● One more thing to maintain
● Slows down development
● Technology not ready
Not a “Silver Bullet” Solution
“With TDD we’ll have no bugs”
“We’ve implemented TDD why
aren’t we going faster?”
Tools of the Trade
React
● JS Library for building user interfaces
● Uses a virtual DOM prior to rendering
to browser’s DOM
Testing Tools
● Test Framework
● Assertion Libraries
● Mocking Library
Example
Essentials:
● React
● Mocha - Test Framework
● Chai - Assertion Library
● Sinon - Mock Library
● Enzyme - React Test Utility
The Stack
Story
Given
Numerical values separated by +
symbols are entered in the
equation field
When
User clicks the equal button
Then
Sum of all numerical values
should display to the right of the
equal button
describe("test addition", () => {
it('simple addition', () => {
//Arrange/Act
const rtnValue = math.parseEquation('1 + 1');
//Assert
expect(rtnValue).to.equal(2);
});
});
7
We connect the digital and physical worlds
export class Math1 {
static parseEquation(equation) {
const addValues = equation.split('+');
let sum = 0;
addValues.forEach((value) => {
sum += value;
});
return sum;
}
}
We connect the digital and physical worlds
7
We connect the digital and physical worlds
export class Math1 {
static parseEquation(equation) {
const addValues = equation.split('+');
let sum = 0;
addValues.forEach((value) => {
sum += value;
});
return sum;
}
}
0 + “1 ” + “ 1” = “01 1”
We connect the digital and physical worlds
export class Math2 {
static parseEquation(equation) {
const addValues = equation.split('+');
let sum = 0;
addValues.forEach((value) => {
sum += parseInt(value.trim());
});
return sum;
}
}
What about React?
We connect the digital and physical worlds
describe('test addition component', () => {
let subject;
let mockParseEquation;
beforeEach(() => {
//Arrange
subject = shallow(<Calculator/>);
mockParseEquation = sinon.stub(math, "parseEquation");
});
afterEach(() => {
mockParseEquation.restore();
});
it('calls math function on click with correct values', () => {
//Arrange
subject.setState({equation:'1 + 1'})
//Act
subject.find('button').simulate('click');
//Assert
expect(mockParseEquation.getCall(0).args[0]).to.equal('1 + 1');
});
...
We connect the digital and physical worlds
...
it('displays result of math utility', () => {
//Arrange
mockParseEquation.returns(2);
//Act
subject.find('button').simulate('click');
//Assert
const resultText = subject.find('.result').text();
expect(resultText).to.equal('2');
});
});
We connect the digital and physical worlds
calculateValue() {
const additionSum = math.parseEquation(this.state.equation);
this.setState({calculatedResult: additionSum});
}
render() {
return (
<div>
<input
value={this.state.equation}
onChange={this.handleValueChange} />
<button onClick={this.calculateValue}>
=
</button>
<label className="result">{this.state.calculatedResult}</label>
</div>
);
}
Building Next Step
We connect the digital and physical worlds
it('invalid input', () => {
//Arrange/Act
const rtnValue = math.parseEquation('1 + one');
//Assert
expect(rtnValue).to.be.NaN;
});
Are We Finished?
We connect the digital and physical worlds
export class Math2 {
static parseEquation(equation) {
const addValues = equation.split('+');
let sum = 0;
addValues.forEach((value) => {
sum += parseInt(value.trim());
});
return sum;
}
}
1 + NaN = NaN
We connect the digital and physical worlds
it('invalid input between numbers', () => {
//Arrange/Act
const rtnValue = math.parseEquation('1 + 123asdf453');
//Assert
expect(rtnValue).to.be.NaN;
});
1 + 123 = 124
We connect the digital and physical worlds
// attempt 3
export class Math3 {
static parseEquation(equation) {
const addValues = equation.split('+');
let sum = 0;
const invalidInput = addValues.some((value) => {
const trimValue = value.trim();
if(!isNaN(parseInt(trimValue)) && isFinite(trimValue)) {
return true;
} else {
sum += parseInt(trimValue);
return false;
}
});
return invalidInput ? NaN : sum;
}
}
We connect the digital and physical worlds
We connect the digital and physical worlds
// attempt 3
export class Math3 {
static parseEquation(equation) {
const addValues = equation.split('+');
let sum = 0;
const invalidInput = addValues.some((value) => {
const trimValue = value.trim();
if(!isNaN(parseInt(trimValue)) && isFinite(trimValue)) {
return true;
} else {
sum += parseInt(trimValue);
return false;
}
});
return invalidInput ? NaN : sum;
}
}
We connect the digital and physical worlds
// attempt 4
export class Math4 {
static parseEquation(equation) {
const addValues = equation.split('+');
let sum = 0;
const invalidInput = addValues.some((value) => {
const trimValue = value.trim();
if(!isNaN(parseInt(trimValue)) && isFinite(trimValue)) {
sum += parseInt(trimValue);
return false;
} else {
return true;
}
});
return invalidInput ? NaN : sum;
}
}
TDD is your Pal!
● Testing doesn’t have to be a bad word
● The flow can feel so natural
● With React TDD can include front end development
Thank you
● https://github.com/Lawton/react-testing-example
● https://medium.com/tribalscale/tutorial-on-testing-react-part-1-2c587e39114d
● https://medium.com/tribalscale/tutorial-on-testing-react-with-tdd-part-2-c50172
bf272e
● http://www.tribalscale.com/blog

Más contenido relacionado

Similar a Intro TDD: Benefits, Tools, React Testing

The lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of testsThe lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of testsScott Wlaschin
 
An introduction to property based testing
An introduction to property based testingAn introduction to property based testing
An introduction to property based testingScott Wlaschin
 
ch04-conditional-execution.ppt
ch04-conditional-execution.pptch04-conditional-execution.ppt
ch04-conditional-execution.pptMahyuddin8
 
STAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Project
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy codeShriKant Vashishtha
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012Sandeep Joshi
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good TestsTomek Kaczanowski
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorNeeraj Kaushik
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanChinmay Chauhan
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksDoug Hawkins
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimizedWoody Pewitt
 
I wrote the following change it to having a header, main and cpp fi.pdf
I wrote the following change it to having a header, main and cpp fi.pdfI wrote the following change it to having a header, main and cpp fi.pdf
I wrote the following change it to having a header, main and cpp fi.pdfrishteygallery
 

Similar a Intro TDD: Benefits, Tools, React Testing (20)

The lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of testsThe lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of tests
 
An introduction to property based testing
An introduction to property based testingAn introduction to property based testing
An introduction to property based testing
 
ch04-conditional-execution.ppt
ch04-conditional-execution.pptch04-conditional-execution.ppt
ch04-conditional-execution.ppt
 
STAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Descartes Presentation
STAMP Descartes Presentation
 
Mutation @ Spotify
Mutation @ Spotify Mutation @ Spotify
Mutation @ Spotify
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Best practices unit testing
Best practices unit testing Best practices unit testing
Best practices unit testing
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression Calculator
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay Chauhan
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's Tricks
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
201506 CSE340 Lecture 12
201506 CSE340 Lecture 12201506 CSE340 Lecture 12
201506 CSE340 Lecture 12
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimized
 
Mutation Testing
Mutation TestingMutation Testing
Mutation Testing
 
Merge sort
Merge sortMerge sort
Merge sort
 
I wrote the following change it to having a header, main and cpp fi.pdf
I wrote the following change it to having a header, main and cpp fi.pdfI wrote the following change it to having a header, main and cpp fi.pdf
I wrote the following change it to having a header, main and cpp fi.pdf
 

Más de FITC

Cut it up
Cut it upCut it up
Cut it upFITC
 
Designing for Digital Health
Designing for Digital HealthDesigning for Digital Health
Designing for Digital HealthFITC
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript PerformanceFITC
 
Surviving Your Tech Stack
Surviving Your Tech StackSurviving Your Tech Stack
Surviving Your Tech StackFITC
 
How to Pitch Your First AR Project
How to Pitch Your First AR ProjectHow to Pitch Your First AR Project
How to Pitch Your First AR ProjectFITC
 
Start by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerStart by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerFITC
 
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryCocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryFITC
 
Everyday Innovation
Everyday InnovationEveryday Innovation
Everyday InnovationFITC
 
HyperLight Websites
HyperLight WebsitesHyperLight Websites
HyperLight WebsitesFITC
 
Everything is Terrifying
Everything is TerrifyingEverything is Terrifying
Everything is TerrifyingFITC
 
Post-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanPost-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanFITC
 
The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)FITC
 
East of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameEast of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameFITC
 
Creating a Proactive Healthcare System
Creating a Proactive Healthcare SystemCreating a Proactive Healthcare System
Creating a Proactive Healthcare SystemFITC
 
World Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignWorld Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignFITC
 
The Power of Now
The Power of NowThe Power of Now
The Power of NowFITC
 
High Performance PWAs
High Performance PWAsHigh Performance PWAs
High Performance PWAsFITC
 
Rise of the JAMstack
Rise of the JAMstackRise of the JAMstack
Rise of the JAMstackFITC
 
From Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFrom Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFITC
 
Projects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForProjects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForFITC
 

Más de FITC (20)

Cut it up
Cut it upCut it up
Cut it up
 
Designing for Digital Health
Designing for Digital HealthDesigning for Digital Health
Designing for Digital Health
 
Profiling JavaScript Performance
Profiling JavaScript PerformanceProfiling JavaScript Performance
Profiling JavaScript Performance
 
Surviving Your Tech Stack
Surviving Your Tech StackSurviving Your Tech Stack
Surviving Your Tech Stack
 
How to Pitch Your First AR Project
How to Pitch Your First AR ProjectHow to Pitch Your First AR Project
How to Pitch Your First AR Project
 
Start by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the AnswerStart by Understanding the Problem, Not by Delivering the Answer
Start by Understanding the Problem, Not by Delivering the Answer
 
Cocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s StoryCocaine to Carrots: The Art of Telling Someone Else’s Story
Cocaine to Carrots: The Art of Telling Someone Else’s Story
 
Everyday Innovation
Everyday InnovationEveryday Innovation
Everyday Innovation
 
HyperLight Websites
HyperLight WebsitesHyperLight Websites
HyperLight Websites
 
Everything is Terrifying
Everything is TerrifyingEverything is Terrifying
Everything is Terrifying
 
Post-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future HumanPost-Earth Visions: Designing for Space and the Future Human
Post-Earth Visions: Designing for Space and the Future Human
 
The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)The Rise of the Creative Social Influencer (and How to Become One)
The Rise of the Creative Social Influencer (and How to Become One)
 
East of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR GameEast of the Rockies: Developing an AR Game
East of the Rockies: Developing an AR Game
 
Creating a Proactive Healthcare System
Creating a Proactive Healthcare SystemCreating a Proactive Healthcare System
Creating a Proactive Healthcare System
 
World Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product DesignWorld Transformation: The Secret Agenda of Product Design
World Transformation: The Secret Agenda of Product Design
 
The Power of Now
The Power of NowThe Power of Now
The Power of Now
 
High Performance PWAs
High Performance PWAsHigh Performance PWAs
High Performance PWAs
 
Rise of the JAMstack
Rise of the JAMstackRise of the JAMstack
Rise of the JAMstack
 
From Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self DiscoveryFrom Closed to Open: A Journey of Self Discovery
From Closed to Open: A Journey of Self Discovery
 
Projects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time ForProjects Ain’t Nobody Got Time For
Projects Ain’t Nobody Got Time For
 

Último

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Último (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

Intro TDD: Benefits, Tools, React Testing

  • 1. An Introduction to TDD Lawton Spelliscy
  • 2. Overview ● The benefits and shortcomings of TDD ● The tools of the trade ● Testing with JS and React
  • 3. TDD 101 ● Write Tests prior to implementation TDD 102 ● Red, Green, Refactor
  • 4. Benefits of Testing ● Tests run fast ● Early step in automated deployment ● Help avoid introducing bugs in greater code base ● Live documentation
  • 5. Benefits of TDD ● Clear, Concise Code ● Minimize context switching ● Catches bugs early ● Better live documentation
  • 6. Frustrations ● Feels unnatural ● One more thing to maintain ● Slows down development ● Technology not ready
  • 7. Not a “Silver Bullet” Solution
  • 8. “With TDD we’ll have no bugs” “We’ve implemented TDD why aren’t we going faster?”
  • 9. Tools of the Trade
  • 10. React ● JS Library for building user interfaces ● Uses a virtual DOM prior to rendering to browser’s DOM
  • 11. Testing Tools ● Test Framework ● Assertion Libraries ● Mocking Library
  • 13.
  • 14. Essentials: ● React ● Mocha - Test Framework ● Chai - Assertion Library ● Sinon - Mock Library ● Enzyme - React Test Utility The Stack
  • 15. Story Given Numerical values separated by + symbols are entered in the equation field When User clicks the equal button Then Sum of all numerical values should display to the right of the equal button
  • 16. describe("test addition", () => { it('simple addition', () => { //Arrange/Act const rtnValue = math.parseEquation('1 + 1'); //Assert expect(rtnValue).to.equal(2); }); });
  • 17.
  • 18. 7 We connect the digital and physical worlds export class Math1 { static parseEquation(equation) { const addValues = equation.split('+'); let sum = 0; addValues.forEach((value) => { sum += value; }); return sum; } }
  • 19. We connect the digital and physical worlds
  • 20. 7 We connect the digital and physical worlds export class Math1 { static parseEquation(equation) { const addValues = equation.split('+'); let sum = 0; addValues.forEach((value) => { sum += value; }); return sum; } } 0 + “1 ” + “ 1” = “01 1”
  • 21. We connect the digital and physical worlds export class Math2 { static parseEquation(equation) { const addValues = equation.split('+'); let sum = 0; addValues.forEach((value) => { sum += parseInt(value.trim()); }); return sum; } }
  • 23. We connect the digital and physical worlds describe('test addition component', () => { let subject; let mockParseEquation; beforeEach(() => { //Arrange subject = shallow(<Calculator/>); mockParseEquation = sinon.stub(math, "parseEquation"); }); afterEach(() => { mockParseEquation.restore(); }); it('calls math function on click with correct values', () => { //Arrange subject.setState({equation:'1 + 1'}) //Act subject.find('button').simulate('click'); //Assert expect(mockParseEquation.getCall(0).args[0]).to.equal('1 + 1'); }); ...
  • 24. We connect the digital and physical worlds ... it('displays result of math utility', () => { //Arrange mockParseEquation.returns(2); //Act subject.find('button').simulate('click'); //Assert const resultText = subject.find('.result').text(); expect(resultText).to.equal('2'); }); });
  • 25. We connect the digital and physical worlds calculateValue() { const additionSum = math.parseEquation(this.state.equation); this.setState({calculatedResult: additionSum}); } render() { return ( <div> <input value={this.state.equation} onChange={this.handleValueChange} /> <button onClick={this.calculateValue}> = </button> <label className="result">{this.state.calculatedResult}</label> </div> ); }
  • 27. We connect the digital and physical worlds it('invalid input', () => { //Arrange/Act const rtnValue = math.parseEquation('1 + one'); //Assert expect(rtnValue).to.be.NaN; });
  • 28.
  • 30. We connect the digital and physical worlds export class Math2 { static parseEquation(equation) { const addValues = equation.split('+'); let sum = 0; addValues.forEach((value) => { sum += parseInt(value.trim()); }); return sum; } } 1 + NaN = NaN
  • 31. We connect the digital and physical worlds it('invalid input between numbers', () => { //Arrange/Act const rtnValue = math.parseEquation('1 + 123asdf453'); //Assert expect(rtnValue).to.be.NaN; }); 1 + 123 = 124
  • 32. We connect the digital and physical worlds // attempt 3 export class Math3 { static parseEquation(equation) { const addValues = equation.split('+'); let sum = 0; const invalidInput = addValues.some((value) => { const trimValue = value.trim(); if(!isNaN(parseInt(trimValue)) && isFinite(trimValue)) { return true; } else { sum += parseInt(trimValue); return false; } }); return invalidInput ? NaN : sum; } }
  • 33. We connect the digital and physical worlds
  • 34. We connect the digital and physical worlds // attempt 3 export class Math3 { static parseEquation(equation) { const addValues = equation.split('+'); let sum = 0; const invalidInput = addValues.some((value) => { const trimValue = value.trim(); if(!isNaN(parseInt(trimValue)) && isFinite(trimValue)) { return true; } else { sum += parseInt(trimValue); return false; } }); return invalidInput ? NaN : sum; } }
  • 35. We connect the digital and physical worlds // attempt 4 export class Math4 { static parseEquation(equation) { const addValues = equation.split('+'); let sum = 0; const invalidInput = addValues.some((value) => { const trimValue = value.trim(); if(!isNaN(parseInt(trimValue)) && isFinite(trimValue)) { sum += parseInt(trimValue); return false; } else { return true; } }); return invalidInput ? NaN : sum; } }
  • 36. TDD is your Pal! ● Testing doesn’t have to be a bad word ● The flow can feel so natural ● With React TDD can include front end development
  • 37. Thank you ● https://github.com/Lawton/react-testing-example ● https://medium.com/tribalscale/tutorial-on-testing-react-part-1-2c587e39114d ● https://medium.com/tribalscale/tutorial-on-testing-react-with-tdd-part-2-c50172 bf272e ● http://www.tribalscale.com/blog