The document provides a summary of a test-driven development walkthrough for a library fine calculation exercise. It outlines setting up the testing framework and files. It then describes the process of writing tests based on requirements, making the tests fail, then passing the tests by implementing minimal code. As more tests are added, the code is refactored to be more generalized through techniques like triangulation. The goal is to use tests to drive the development of production code in a iterative cycle.
The document is a walkthrough of using test-driven development (TDD) to solve an encryption problem. It begins by setting up test and source code files. Tests are written based on examples from the problem. Minimal code is written to pass each test. Refactoring improves the code while maintaining passing tests. The implementation is generalized through many small iterative changes. Edge cases are addressed, like when the encryption grid is too small. The completed solution passes all tests.
Seconda serata di introduzione al Test-Driven Development, tenuta in XPeppers a Trento il 24 Ottobre 2012.
Nelle slide c'è anche la descrizione del coding dojo sullo string calculator che abbiamo svolto assieme.
Ryktene om TDDs død er sterkt overdrevet, men det har skjedd mye inn test-drevet utvikling siden Kent Beck introduserte TDD med Extreme Programming i 1999. TDD, BDD, ATDD, ST, DDT … hvordan passer alt dette sammen? Hva skal til for å lykkes med automatisert testing?
This document provides an introduction to Test Driven Development (TDD). It explains that TDD is a software development technique where unit tests are written before code to test specific functionality. The key steps of TDD are to write a failing test, write just enough code to pass the test, then refactor the code. Following this process helps ensure code quality and prevents regressions when changing code. The document provides examples of writing unit tests and code using a TDD approach.
TDD involves writing tests before code to verify functionality. The process is:
1. Write a test that fails without the target code implemented.
2. Write the minimum code required for the test to pass.
3. Refactor the code as needed to improve design while ensuring tests still pass.
The goal is to use tests to drive code development and prevent regressions, with tests providing feedback on potential design issues. TDD encourages writing code in small, testable units and helps developers learn through practice.
This document summarizes a TDD walkthrough for converting times to words. It begins by setting up the necessary files and frameworks. The first test case converts 5:00 to "five o' clock" and fails initially. Code is then written to pass this test. Additional tests are added for other times like 5:30 and 5:15, with code changes to pass each new test while maintaining previous tests. Refactoring removes duplication, leading to cleaner code structure using variables and objects. The walkthrough demonstrates a step-by-step TDD process.
This document summarizes notes from Kent Beck's book "TDD by Example" on test-driven development (TDD). It outlines the core principles of TDD, including writing tests first before code and eliminating duplication. It also describes techniques like red-green-refactor cycles where tests are written to fail initially ("red"), made to pass ("green"), and then code is refactored. The document provides examples of applying TDD to a money conversion problem and discusses patterns for testing, refactoring, and overcoming fears that arise during the process.
Beyond Testing: Specs and Behavior Driven DevelopmentRabble .
This document discusses testing approaches for software development, including:
1. It begins by describing traditional QA testing from the perspective of a programmer, noting it finds major problems but is extra work.
2. It then introduces the concept of regression testing in code to automatically verify functionality. Unit testing is described as the most common type of regression testing.
3. The document advocates for behavior driven development (BDD) which focuses on testing functionality and desired behavior rather than implementation details, using "should" statements rather than asserts. This helps avoid issues when code changes but functionality does not.
The document is a walkthrough of using test-driven development (TDD) to solve an encryption problem. It begins by setting up test and source code files. Tests are written based on examples from the problem. Minimal code is written to pass each test. Refactoring improves the code while maintaining passing tests. The implementation is generalized through many small iterative changes. Edge cases are addressed, like when the encryption grid is too small. The completed solution passes all tests.
Seconda serata di introduzione al Test-Driven Development, tenuta in XPeppers a Trento il 24 Ottobre 2012.
Nelle slide c'è anche la descrizione del coding dojo sullo string calculator che abbiamo svolto assieme.
Ryktene om TDDs død er sterkt overdrevet, men det har skjedd mye inn test-drevet utvikling siden Kent Beck introduserte TDD med Extreme Programming i 1999. TDD, BDD, ATDD, ST, DDT … hvordan passer alt dette sammen? Hva skal til for å lykkes med automatisert testing?
This document provides an introduction to Test Driven Development (TDD). It explains that TDD is a software development technique where unit tests are written before code to test specific functionality. The key steps of TDD are to write a failing test, write just enough code to pass the test, then refactor the code. Following this process helps ensure code quality and prevents regressions when changing code. The document provides examples of writing unit tests and code using a TDD approach.
TDD involves writing tests before code to verify functionality. The process is:
1. Write a test that fails without the target code implemented.
2. Write the minimum code required for the test to pass.
3. Refactor the code as needed to improve design while ensuring tests still pass.
The goal is to use tests to drive code development and prevent regressions, with tests providing feedback on potential design issues. TDD encourages writing code in small, testable units and helps developers learn through practice.
This document summarizes a TDD walkthrough for converting times to words. It begins by setting up the necessary files and frameworks. The first test case converts 5:00 to "five o' clock" and fails initially. Code is then written to pass this test. Additional tests are added for other times like 5:30 and 5:15, with code changes to pass each new test while maintaining previous tests. Refactoring removes duplication, leading to cleaner code structure using variables and objects. The walkthrough demonstrates a step-by-step TDD process.
This document summarizes notes from Kent Beck's book "TDD by Example" on test-driven development (TDD). It outlines the core principles of TDD, including writing tests first before code and eliminating duplication. It also describes techniques like red-green-refactor cycles where tests are written to fail initially ("red"), made to pass ("green"), and then code is refactored. The document provides examples of applying TDD to a money conversion problem and discusses patterns for testing, refactoring, and overcoming fears that arise during the process.
Beyond Testing: Specs and Behavior Driven DevelopmentRabble .
This document discusses testing approaches for software development, including:
1. It begins by describing traditional QA testing from the perspective of a programmer, noting it finds major problems but is extra work.
2. It then introduces the concept of regression testing in code to automatically verify functionality. Unit testing is described as the most common type of regression testing.
3. The document advocates for behavior driven development (BDD) which focuses on testing functionality and desired behavior rather than implementation details, using "should" statements rather than asserts. This helps avoid issues when code changes but functionality does not.
This document discusses best practices for test-driven development (TDD). It begins by describing the different types of tests - unit, integration, and acceptance. It then discusses the debate around having more unit tests vs acceptance tests. The document argues that less acceptance tests and more unit tests leads to faster, higher quality code. The rest of the document outlines five rules for writing effective tests: 1) Write tests before coding, 2) Don't test everything, 3) Test only public APIs, 4) Don't create extra getters for testing, and 5) Listen to what your tests are telling you about your code quality and design.
The document discusses test-driven development (TDD) and refactoring. It explains what TDD is, how to implement it in three steps - writing a failing test, making the test pass, and refactoring code - and provides an example of modeling a calendar to track holidays using TDD. The document also discusses benefits of TDD like catching mistakes early, increasing coding confidence, and making it easier to implement new requirements through refactoring.
Just Enough Testing presentation from TestIL meetup 2018,
Also presented in QAGeekWeek and SIGiST 2017
How can we improve our testing process making it leaner on one side but not neglecting Quality on the other?
Written as tips and procedures from over 20 years of experience as SW Tester and group leader,
These are highlights of my talk, for further details - feel free to invite Me to expend the details in 2 hours or more lecture :-)
TDD and agile methods originated from attempts to manage large software projects more effectively. TDD involves writing automated tests before code to specify requirements and catch errors early. It helps avoid major redesigns later. Tests should fail initially and then code is written to pass the test, followed by refactoring. Patterns like starting simply, faking dependencies, and generalizing from examples help get code passing tests quickly. Pitfalls include not starting with a failing test or refactoring tests improperly. The session covered TDD history and techniques, with examples and opportunities for further learning.
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...Abdelkrim Boujraf
The document discusses the authors' experience with different testing strategies at their company StratEx. They initially used Selenium for UI testing but found it did not help when they frequently changed screens. They then investigated Test-Driven Development (TDD) but found it inefficient, as tests are also code that must be written and maintained. Behavior-Driven Development (BDD) showed more promise as it focuses on functionality rather than architecture and bridges communication between users and developers. However, no methodology fully describes large, complex systems. The search for the best testing approach is ongoing.
Pairing software developers with testers can improve code quality and productivity. The document describes a case where a developer, Marty, paired with a tester, Lanette, to integrate testing earlier in the development process. By explaining code changes to Lanette and incorporating her test ideas, Marty's code became more stable and automated testing was added. Both parties' skills benefited from the collaboration. The document advocates for occasional pairing rather than mandates, and provides tips for making pairing work effectively within teams.
Blackboxtesting 02 An Example Test Seriesnazeer pasha
1. The document describes an example test series for a simple program that adds two numbers entered by the user.
2. It outlines the initial testing process, including performing simple tests, exploring all parts of the program, looking for more challenging tests, and focusing on boundary conditions.
3. The document discusses techniques for test design such as brainstorming test cases, equivalence partitioning, and boundary value analysis to identify important tests without testing all possible combinations.
The document argues that unit test scopes should be larger rather than having many small unit test classes. Larger unit tests are better because they are less tightly coupled to code structure, can be more easily mapped to business requirements, and test interactions between classes rather than just individual classes. The document provides suggestions for how to structure unit tests at a bigger scope, such as using dependency injection frameworks, test data builders, and splitting tests across multiple classes when there are too many assertions. The overall message is that test scopes should be large enough to cover layers, external libraries, and controllers when possible rather than focusing exclusively on small individual classes.
TDD involves writing tests before writing code to satisfy requirements. The document discusses TDD, providing:
1. An overview of the TDD process and definitions of its key steps - make a test, make it fail, make it pass.
2. An example walking through writing a test for an "easy button" and implementing the code to pass the test.
3. Reasons for using TDD, including improved code quality, design, discipline, and documentation from maintaining an automated test suite.
I'm a TDD cheat and I'm not afraid to admit itDaniel Irvine
The document discusses test-driven development (TDD) and various "shortcuts" and "cheats" that can be used when following a TDD workflow. It defines strict TDD as writing 100% of code according to TDD rules and identifies 8 common shortcuts or cheats people use, such as skipping running tests on red code or prematurely refactoring code before having multiple test cases. The author advocates modifying the TDD workflow to suit one's needs and finding joy in programming, noting that using shortcuts does not preclude being a good practitioner of TDD principles overall.
The document discusses refactoring tips provided by Martin Fowler. It defines refactoring as improving the internal structure of software without changing its external behavior. It provides examples of common refactoring techniques like extract method, inline method, move method, and consolidate conditional expressions. The goal of refactoring is to improve code quality by making software easier to understand and modify over time.
TDD, the way to better software | Dan Ursu | CodeWay 2015YOPESO
Watch this presentation if you want to know what problems TDD (Test-Driven Development) solves for developers, project managers and the clients in charge of software products.
Watch the video here:
https://www.youtube.com/watch?v=bxk1i-PC-1Q
The code used for the demo:
https://github.com/yopeso/CodeWayTDDFearlessRefactor
This document discusses testing in Scrum projects. It cannot be avoided, but can be minimized. Putting testers in the Scrum team increases quality by having developers tested by experts. Doing less per sprint also increases quality. Acceptance testing may require its own phase after sprints. Prioritize fixing old bugs found before starting new work. Alleviate bottlenecks by increasing test automation, adding testers, or adjusting sprint length. True cross-functional teams share testing duties.
This document contains a private profile listing various freelance projects completed by the individual, along with notes on studying programming languages and taking tests to add to their Upwork profile. It discusses strategies for applying to jobs, setting earnings targets, searching for suitable positions, and optimizing their hire rate and success on the platform.
The document discusses refactoring legacy code for a client project. It describes steps taken to refactor code for searching products and handling file attachments. For searching, the speaker extracted parameters from a method with 21 parameters and 200 lines of code into a builder pattern. For attachments, switch statements were replaced with polymorphism, and file processing logic was extracted from a service into separate classes. The refactoring was done incrementally using test-driven development practices learned at coderetreats. Tests were added to verify changes at each step, and over 30 commits were made. The refactoring provided value to customers while improving code quality and maintainability.
A Software Tester's Travels from the Land of the Waterfall to the Land of Agi...Yuval Yeret
In my work, I have come across many software testing organizations/groups. Some use the waterfall method and may be in the first stages of exposure to Agile-based methods. Some are on the journey to switch between methods, and some have already been using Agile and are looking for ways to do this more effectively. In this article, I will try to describe the experience of a typical software tester when his organization decides to move to Agile.
Note: This is an english translation of a "Thinking Testing" hebrew magazine article from 2012
The original promise of TDD was that it would assist in guiding the development of clean code, but it often ends up polluting our architecture with excessive composition, is expensive to write, and becomes an obstacle to change, not an aid to refactoring. In this talk, we look at the fallacies of TDD and learn about the key principles that we should be following for mastery of this practice. This talk is intended for those who have been practicing TDD, or who have tried TDD and given up because of shortcomings in the approach they were taught.
Mobile App Development Company In Noida | Drona InfotechDrona Infotech
Drona Infotech is a premier mobile app development company in Noida, providing cutting-edge solutions for businesses.
Visit Us For : https://www.dronainfotech.com/mobile-application-development/
This document discusses best practices for test-driven development (TDD). It begins by describing the different types of tests - unit, integration, and acceptance. It then discusses the debate around having more unit tests vs acceptance tests. The document argues that less acceptance tests and more unit tests leads to faster, higher quality code. The rest of the document outlines five rules for writing effective tests: 1) Write tests before coding, 2) Don't test everything, 3) Test only public APIs, 4) Don't create extra getters for testing, and 5) Listen to what your tests are telling you about your code quality and design.
The document discusses test-driven development (TDD) and refactoring. It explains what TDD is, how to implement it in three steps - writing a failing test, making the test pass, and refactoring code - and provides an example of modeling a calendar to track holidays using TDD. The document also discusses benefits of TDD like catching mistakes early, increasing coding confidence, and making it easier to implement new requirements through refactoring.
Just Enough Testing presentation from TestIL meetup 2018,
Also presented in QAGeekWeek and SIGiST 2017
How can we improve our testing process making it leaner on one side but not neglecting Quality on the other?
Written as tips and procedures from over 20 years of experience as SW Tester and group leader,
These are highlights of my talk, for further details - feel free to invite Me to expend the details in 2 hours or more lecture :-)
TDD and agile methods originated from attempts to manage large software projects more effectively. TDD involves writing automated tests before code to specify requirements and catch errors early. It helps avoid major redesigns later. Tests should fail initially and then code is written to pass the test, followed by refactoring. Patterns like starting simply, faking dependencies, and generalizing from examples help get code passing tests quickly. Pitfalls include not starting with a failing test or refactoring tests improperly. The session covered TDD history and techniques, with examples and opportunities for further learning.
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...Abdelkrim Boujraf
The document discusses the authors' experience with different testing strategies at their company StratEx. They initially used Selenium for UI testing but found it did not help when they frequently changed screens. They then investigated Test-Driven Development (TDD) but found it inefficient, as tests are also code that must be written and maintained. Behavior-Driven Development (BDD) showed more promise as it focuses on functionality rather than architecture and bridges communication between users and developers. However, no methodology fully describes large, complex systems. The search for the best testing approach is ongoing.
Pairing software developers with testers can improve code quality and productivity. The document describes a case where a developer, Marty, paired with a tester, Lanette, to integrate testing earlier in the development process. By explaining code changes to Lanette and incorporating her test ideas, Marty's code became more stable and automated testing was added. Both parties' skills benefited from the collaboration. The document advocates for occasional pairing rather than mandates, and provides tips for making pairing work effectively within teams.
Blackboxtesting 02 An Example Test Seriesnazeer pasha
1. The document describes an example test series for a simple program that adds two numbers entered by the user.
2. It outlines the initial testing process, including performing simple tests, exploring all parts of the program, looking for more challenging tests, and focusing on boundary conditions.
3. The document discusses techniques for test design such as brainstorming test cases, equivalence partitioning, and boundary value analysis to identify important tests without testing all possible combinations.
The document argues that unit test scopes should be larger rather than having many small unit test classes. Larger unit tests are better because they are less tightly coupled to code structure, can be more easily mapped to business requirements, and test interactions between classes rather than just individual classes. The document provides suggestions for how to structure unit tests at a bigger scope, such as using dependency injection frameworks, test data builders, and splitting tests across multiple classes when there are too many assertions. The overall message is that test scopes should be large enough to cover layers, external libraries, and controllers when possible rather than focusing exclusively on small individual classes.
TDD involves writing tests before writing code to satisfy requirements. The document discusses TDD, providing:
1. An overview of the TDD process and definitions of its key steps - make a test, make it fail, make it pass.
2. An example walking through writing a test for an "easy button" and implementing the code to pass the test.
3. Reasons for using TDD, including improved code quality, design, discipline, and documentation from maintaining an automated test suite.
I'm a TDD cheat and I'm not afraid to admit itDaniel Irvine
The document discusses test-driven development (TDD) and various "shortcuts" and "cheats" that can be used when following a TDD workflow. It defines strict TDD as writing 100% of code according to TDD rules and identifies 8 common shortcuts or cheats people use, such as skipping running tests on red code or prematurely refactoring code before having multiple test cases. The author advocates modifying the TDD workflow to suit one's needs and finding joy in programming, noting that using shortcuts does not preclude being a good practitioner of TDD principles overall.
The document discusses refactoring tips provided by Martin Fowler. It defines refactoring as improving the internal structure of software without changing its external behavior. It provides examples of common refactoring techniques like extract method, inline method, move method, and consolidate conditional expressions. The goal of refactoring is to improve code quality by making software easier to understand and modify over time.
TDD, the way to better software | Dan Ursu | CodeWay 2015YOPESO
Watch this presentation if you want to know what problems TDD (Test-Driven Development) solves for developers, project managers and the clients in charge of software products.
Watch the video here:
https://www.youtube.com/watch?v=bxk1i-PC-1Q
The code used for the demo:
https://github.com/yopeso/CodeWayTDDFearlessRefactor
This document discusses testing in Scrum projects. It cannot be avoided, but can be minimized. Putting testers in the Scrum team increases quality by having developers tested by experts. Doing less per sprint also increases quality. Acceptance testing may require its own phase after sprints. Prioritize fixing old bugs found before starting new work. Alleviate bottlenecks by increasing test automation, adding testers, or adjusting sprint length. True cross-functional teams share testing duties.
This document contains a private profile listing various freelance projects completed by the individual, along with notes on studying programming languages and taking tests to add to their Upwork profile. It discusses strategies for applying to jobs, setting earnings targets, searching for suitable positions, and optimizing their hire rate and success on the platform.
The document discusses refactoring legacy code for a client project. It describes steps taken to refactor code for searching products and handling file attachments. For searching, the speaker extracted parameters from a method with 21 parameters and 200 lines of code into a builder pattern. For attachments, switch statements were replaced with polymorphism, and file processing logic was extracted from a service into separate classes. The refactoring was done incrementally using test-driven development practices learned at coderetreats. Tests were added to verify changes at each step, and over 30 commits were made. The refactoring provided value to customers while improving code quality and maintainability.
A Software Tester's Travels from the Land of the Waterfall to the Land of Agi...Yuval Yeret
In my work, I have come across many software testing organizations/groups. Some use the waterfall method and may be in the first stages of exposure to Agile-based methods. Some are on the journey to switch between methods, and some have already been using Agile and are looking for ways to do this more effectively. In this article, I will try to describe the experience of a typical software tester when his organization decides to move to Agile.
Note: This is an english translation of a "Thinking Testing" hebrew magazine article from 2012
The original promise of TDD was that it would assist in guiding the development of clean code, but it often ends up polluting our architecture with excessive composition, is expensive to write, and becomes an obstacle to change, not an aid to refactoring. In this talk, we look at the fallacies of TDD and learn about the key principles that we should be following for mastery of this practice. This talk is intended for those who have been practicing TDD, or who have tried TDD and given up because of shortcomings in the approach they were taught.
Mobile App Development Company In Noida | Drona InfotechDrona Infotech
Drona Infotech is a premier mobile app development company in Noida, providing cutting-edge solutions for businesses.
Visit Us For : https://www.dronainfotech.com/mobile-application-development/
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...XfilesPro
Wondering how X-Sign gained popularity in a quick time span? This eSign functionality of XfilesPro DocuPrime has many advancements to offer for Salesforce users. Explore them now!
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsPeter Muessig
The UI5 tooling is the development and build tooling of UI5. It is built in a modular and extensible way so that it can be easily extended by your needs. This session will showcase various tooling extensions which can boost your development experience by far so that you can really work offline, transpile your code in your project to use even newer versions of EcmaScript (than 2022 which is supported right now by the UI5 tooling), consume any npm package of your choice in your project, using different kind of proxies, and even stitching UI5 projects during development together to mimic your target environment.
Consistent toolbox talks are critical for maintaining workplace safety, as they provide regular opportunities to address specific hazards and reinforce safe practices.
These brief, focused sessions ensure that safety is a continual conversation rather than a one-time event, which helps keep safety protocols fresh in employees' minds. Studies have shown that shorter, more frequent training sessions are more effective for retention and behavior change compared to longer, infrequent sessions.
Engaging workers regularly, toolbox talks promote a culture of safety, empower employees to voice concerns, and ultimately reduce the likelihood of accidents and injuries on site.
The traditional method of conducting safety talks with paper documents and lengthy meetings is not only time-consuming but also less effective. Manual tracking of attendance and compliance is prone to errors and inconsistencies, leading to gaps in safety communication and potential non-compliance with OSHA regulations. Switching to a digital solution like Safelyio offers significant advantages.
Safelyio automates the delivery and documentation of safety talks, ensuring consistency and accessibility. The microlearning approach breaks down complex safety protocols into manageable, bite-sized pieces, making it easier for employees to absorb and retain information.
This method minimizes disruptions to work schedules, eliminates the hassle of paperwork, and ensures that all safety communications are tracked and recorded accurately. Ultimately, using a digital platform like Safelyio enhances engagement, compliance, and overall safety performance on site. https://safelyio.com/
E-commerce Development Services- Hornet DynamicsHornet Dynamics
For any business hoping to succeed in the digital age, having a strong online presence is crucial. We offer Ecommerce Development Services that are customized according to your business requirements and client preferences, enabling you to create a dynamic, safe, and user-friendly online store.
Project Management: The Role of Project Dashboards.pdfKarya Keeper
Project management is a crucial aspect of any organization, ensuring that projects are completed efficiently and effectively. One of the key tools used in project management is the project dashboard, which provides a comprehensive view of project progress and performance. In this article, we will explore the role of project dashboards in project management, highlighting their key features and benefits.
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesQuickdice ERP
Explore the seamless transition to e-invoicing with this comprehensive guide tailored for Saudi Arabian businesses. Navigate the process effortlessly with step-by-step instructions designed to streamline implementation and enhance efficiency.
How Can Hiring A Mobile App Development Company Help Your Business Grow?ToXSL Technologies
ToXSL Technologies is an award-winning Mobile App Development Company in Dubai that helps businesses reshape their digital possibilities with custom app services. As a top app development company in Dubai, we offer highly engaging iOS & Android app solutions. https://rb.gy/necdnt
8 Best Automated Android App Testing Tool and Framework in 2024.pdfkalichargn70th171
Regarding mobile operating systems, two major players dominate our thoughts: Android and iPhone. With Android leading the market, software development companies are focused on delivering apps compatible with this OS. Ensuring an app's functionality across various Android devices, OS versions, and hardware specifications is critical, making Android app testing essential.
UI5con 2024 - Bring Your Own Design SystemPeter Muessig
How do you combine the OpenUI5/SAPUI5 programming model with a design system that makes its controls available as Web Components? Since OpenUI5/SAPUI5 1.120, the framework supports the integration of any Web Components. This makes it possible, for example, to natively embed own Web Components of your design system which are created with Stencil. The integration embeds the Web Components in a way that they can be used naturally in XMLViews, like with standard UI5 controls, and can be bound with data binding. Learn how you can also make use of the Web Components base class in OpenUI5/SAPUI5 to also integrate your Web Components and get inspired by the solution to generate a custom UI5 library providing the Web Components control wrappers for the native ones.
Malibou Pitch Deck For Its €3M Seed Roundsjcobrien
French start-up Malibou raised a €3 million Seed Round to develop its payroll and human resources
management platform for VSEs and SMEs. The financing round was led by investors Breega, Y Combinator, and FCVC.
Microservice Teams - How the cloud changes the way we workSven Peters
A lot of technical challenges and complexity come with building a cloud-native and distributed architecture. The way we develop backend software has fundamentally changed in the last ten years. Managing a microservices architecture demands a lot of us to ensure observability and operational resiliency. But did you also change the way you run your development teams?
Sven will talk about Atlassian’s journey from a monolith to a multi-tenanted architecture and how it affected the way the engineering teams work. You will learn how we shifted to service ownership, moved to more autonomous teams (and its challenges), and established platform and enablement teams.
2. TDD Walkthrough - Library Fine
Hello and welcome to my TDD Walkthrough!
Today’s exercise is Library Fine, taken from
HackerRank.com at the following URL:
https://www.hackerrank.com/challenges/library-fi
ne/problem
3. TDD Walkthrough - Library Fine
In these TDD Walkthroughs, I assume that my
readers have basic knowledge of test driven
development. I highly suggest having an
understanding of TDD before going through this
walkthrough. The following blog post explains
the cycles of TDD.
http://blog.cleancoder.com/uncle-bob/2014/12/1
7/TheCyclesOfTDD.html
I also assume that my readers have knowledge
of refactoring tools and terminology. If you need
more information, this blog post on the six core
refactorings will provide enough information.
http://arlobelshee.com/the-core-6-refactorings/
4. TDD Walkthrough - Library Fine
For this exercise, I have the following already set up:
Chrome browser
Visual Studio Code or your personal IDE
Jasmine testing framework
(see my other blog on setting up: https://www.greatersum.com/tdd-setup-jasmine/)
With the above already set up, let’s get started!
5. TDD Walkthrough - Library Fine
This walkthrough starts with an already set up
Jasmine standalone project from my other blog
post.
From there, I will create the file that contains my
tests.
6. TDD Walkthrough - Library Fine
There are various conventions for file names out
there. I tend to use the affectionately dubbed
kabob-case: library-fine.spec.js
7. TDD Walkthrough - Library Fine
This is a spec file. This file needs to be included
in the Jasmine spec runner, so open up the
SpecRunner.html file next.
Look for the comment that says “include spec
files here”, and include the spec file you just
created.
8. TDD Walkthrough - Library Fine
We are now ready to write tests. Which tests do
we write? Let’s start a test list.
The first rule of Library Fine talks about books
returned on or before the due date. What kinds
of tests can come from this? I can think of 2.
First, the book is returned today Jan 08, 2018
and it is due tomorrow Jan 09, 2018. It is
returned before the due date, so no fee is due.
Second, the book is returned today Jan 08,
2018 and it is due today Jan 08, 2018. It is
returned on the due date, and no fee is due.
Returned 01/08/2018
Due 01/09/2018
No Fee Due
Returned 01/08/2018
Due 01/08/2018
No Fee Due
9. TDD Walkthrough - Library Fine
For the second rule, let’s say a book is returned
Jan 08, 2018 and it was due Jan 07, 2018. It is
one day late, which means 15 Hackos are due.
For the third rule, let’s say a book is returned
Feb 08, 2018 and it was due Jan 08, 2018. It
was due the previous month, which means 500
Hackos are due.
For the last rule, we’ll say a book was returned
Jan 01, 2019 and it was due Jan 08, 2018. It
was returned after the calendar year it was due
and thus 10000 Hackos are due.
Returned 01/08/2018
Due 01/07/2018
15 Hackos Due
Returned 02/08/2018
Due 01/08/2018
500 Hackos Due
Returned 01/01/2019
Due 01/08/2018
10000 Hackos Due
10. TDD Walkthrough - Library Fine
This test list looks like it covers all the rules for the Library Fine exercise. We have enough to get started.
Returned 01/08/2018, Due 01/09/2018, No Fee Due
Returned 01/08/2018, Due 01/08/2018, No Fee Due
Returned 01/08/2018, Due 01/07/2018, 15 Hackos Due
Returned 02/08/2018, Due 01/08/2018, 500 Hackos Due
Returned 01/01/2019, Due 01/08/2018, 10000 Hackos Due
11. TDD Walkthrough - Library Fine
Let’s write our first test. First, we create the test
suite:
And then we write the test function:
In our test function, we write what we are
expecting:
12. TDD Walkthrough - Library Fine
At this point, you should be able to run your test runner HTML file by opening it in
the browser, and see a failing test.
Failing the test here is good! You haven’t written any production code yet, and
that’s ok. What you did write is a test that will tell you when your code fulfilled a
purpose, and that is to return a fee of 0 when the book returned before the due
date. It’s not much, but we take one step at a time.
13. TDD Walkthrough - Library Fine
Ok, so what does the test runner say?
libraryFine is not defined. That makes sense, we
haven’t written anything called libraryFine yet.
Let’s go make that function!
14. TDD Walkthrough - Library Fine
To keep the code organized well, the tests are
contained in the spec file, in the spec folder.
So then our source code should go in the source
folder!
15. TDD Walkthrough - Library Fine
Our new source file will need to be included in
the Spec Runner though, so let’s not forget to do
that.
16. TDD Walkthrough - Library Fine
Now back to our source file. The first issue is
that theTimeInWords is not defined, so let’s go
define it.
17. TDD Walkthrough - Library Fine
You might be tempted to go implement all of the function right now. But bear with
me and take one small step at a time. Let’s focus on the error at hand, and we’ll
tackle each issue as they come up. That way we don’t write extra code for no
reason.
This is, after all, development that is driven by testing. So run the tests again. You
can rerun the tests by refreshing the spec runner page.
18. TDD Walkthrough - Library Fine
Ok, different error message. Expected
undefined to be 0.
Well, the solution sounds simple. Make our
function return 0!
19. TDD Walkthrough - Library Fine
This solution will make you cringe. It makes me cringe.
But you never write more code than you need. That prevents you from wasting
time on extra code, and it prevents you from writing code that can break other
things in other ways.
Focus on minimal design, and drive your code towards the functionality you want
with tests.
20. TDD Walkthrough - Library Fine
Ok, that being said, our current test should pass.
And it does! Good, we move on to the next test
on our list.
21. TDD Walkthrough - Library Fine
With the first test case done, let’s do the second
case: book returned and due on Jan 08, 2018.
Run the tests, and it appears we’re already
passing? Wait, that’s unexpected. If we were
following the TDD cycle, our new test should be
failing.
22. TDD Walkthrough - Library Fine
This second test was already passing because what we did for the first test fulfilled
the second test. This means our second test doesn’t add anything new to
production code. How useful is our second test then?
It is normal during TDD to change your test list as you discover new things. Your
test list is not perfect. It is a work in progress, and that is okay.
So what do we do with this already passing test? People have different
approaches. You can take it out. You can keep it there. If the situation fits, you can
also put it together with another test.
23. TDD Walkthrough - Library Fine
I will combine the second test with the first test.
The reasoning here is that the return from the
function is expected to be the same for both
cases, which is 0. Also, it was the production
code from the first test that made the second
test pass, so it is reasonable to say the first test
and second test are relatable and can be
combined.
24. TDD Walkthrough - Library Fine
Ok! First and second tests are out of the way, so
on to the third test. After making a major change
like that, run the tests to make sure everything is
passing.
Once that is green, move on to the third test!
For this test, 15 Hackos are due when the
returned book is 1 day late. So we expect 15
when we put in the dates Jan 08 2018 and Jan
07 2018.
25. TDD Walkthrough - Library Fine
Run the tests, and we have 1 passing and 1
failing test. This is shown in the upper left corner
as 1 green dot for the first/second test, and 1
red dot for the third test. Our new test is failing,
as expected.
Because the tests in the spec file don’t line up
with the test list, there may be some confusion
as to which test is which. Going forward, I only
refer to tests in the spec file unless otherwise
indicated. So our spec file has a first test, and
the new second test that we need to get
passing. Without failing the first one.
26. TDD Walkthrough - Library Fine
So how do we pass the second test, the fastest
way possible? The most straightforward way
would be, if the dates passed in are Jan 8 2018
and Jan 7 2018, then return 15.
Is this the implementation we want in the end?
Definitely no. But this implementation gets us
the passing test.
Now that our test is passing, we will fix this
implementation to work for all general cases.
27. TDD Walkthrough - Library Fine
The next step is to refactor. Specifically we want to generalize the implementation
for the second test, 15 Hackos per day the book is returned late.
What we have right now is called “fake it”. Our production code will pass the test
we wrote, but it doesn’t cover all the cases.
How do we change the code to cover all cases? There are two common
approaches: the Obvious Implementation, or Triangulation.
Triangulation is a method of taking small steps by writing additional tests. These
additional tests give clues to what the general implementation is. Use those clues
to make the appropriate changes. I will demonstrate this on the second test.
28. TDD Walkthrough - Library Fine
We should come up with another test case that
we know will fail, and is in the same category as
the second test. Let’s say a book is two days
late, and the fee due is 30 Hackos.
And we expect our new test to fail.
29. TDD Walkthrough - Library Fine
The fastest solution here will look like the last
one. If the dates look like this, then return 30.
Make sure the tests pass, then we can move on
to refactoring.
Now that we have two cases of the same rule,
we can look for a pattern and see if we can
refactor to better code.
For one thing, we know the fees due are
calculated as days overdue times 15. One step
at a time, we start by rewriting 30 as 2 * 15, and
15 as 1 * 15. Make sure you didn’t break
anything by rerunning the tests.
30. TDD Walkthrough - Library Fine
The 2 in 2 * 15 comes from the difference in
days between the return date and due date.
That is also true for the 1 in 1 * 15. The path to
better code in this case is to calculate the
difference in days between the two dates.
I start off by separating the return date and the
due date.
Then I assign each date to its own variable.
Then I fetch the day in each date.
The date starts as a string, so I need to convert
the days from strings to integers.
31. TDD Walkthrough - Library Fine
Now, I can calculate the fees due from the days
overdue. The return day minus the due day
gives the number of days overdue. Try that for
one case, make sure that passes.
Then do the same change for the other case,
and see that pass the tests too.
These two cases return the same thing now.
This means we can combine them. Do this by
putting the conditionals together. Remember,
when you make changes, run the tests!
32. TDD Walkthrough - Library Fine
We have this combined conditional, which is a
really long piece of code that is trying to say
something. What is it trying to say? If the day
returned is after the day due right? So then if the
day returned is greater than the day due, then
return number of days overdue times 15. That
sounds like our rule!
This may have seemed like a long winded
approach to this case. And it probably is,
considering how simple this rule is. When you
are confident in coding a simple piece of logic,
you can try to perform the Obvious
Implementation, which I will demonstrate.
33. TDD Walkthrough - Library Fine
A little cleaning up first, combining the test
cases of the second test.
Onto the next test case, which is overdue books
returned in the same year but different months.
From our test list, the test case we are using is a
book returned Feb 8 2018 and due on Jan 8
2018. 500 Hackos is due. Your tests should fail
at this time.
34. TDD Walkthrough - Library Fine
How to implement this? The third rule is very
similar to the second rule, except we calculate
the fee as the difference in months times 500
Hackos. We can borrow some of the code from
the second rule to implement the third rule. Get
the months from each date, and use their
difference to calculate the fee. The code for third
rule looks very much like the second rule, and
the tests pass!
While the obvious implementation worked out
this time, whenever you use this technique you
must be prepared to fix any special cases you
may have missed in your implementation.
35. TDD Walkthrough - Library Fine
Now for the last rule: a flat fee of 10000 Hackos
for overdue books returned in a later year. The
test case we chose for this rule is a book
returned Jan 1 2019 that was due on Jan 8
2018. 10000 Hackos are due.
36. TDD Walkthrough - Library Fine
The solution for this is fairly straightforward. As
long as the year returned is after the year due,
there is a flat fee of 10000 Hackos. We will need
to get the year numbers from the dates. It takes
a little string manipulation, but it will work. Once
you have the year numbers, the logic is about
the same as the other 2 rules we did earlier.
We have now passed tests for all 4 rules of the
Library Fine exercise! We have covered every
case on our test list.
37. TDD Walkthrough - Library Fine
You might notice that there are some cases that we do not pass. I left them out on
purpose so that you can go through the exercise yourself! The production code in
this walkthrough will not work when the days and months are double digits. I
suggest that you come up with your own, more comprehensive test list, and try to
use test driven development yourself to solve all cases of the Library Fine
problem. Good Luck!
38. TDD Walkthrough - Library Fine
For those who want to look at the source code, I have this walkthrough posted on
github here:
https://github.com/khapeterk/TDDWalkthroughLibraryFine