The document discusses unit testing principles and purposes. It states that unit testing is used to prove that classes work properly in isolation, catch bugs early, enforce high-quality code, and make refactoring safer. Unit testing encourages modular and loosely coupled code. However, it does not replace integration or system testing and not all code can be unit tested. The document also provides examples of when code should be refactored before writing unit tests.
The presentation contains a definition and survey of the benefits of Unit Testing, and a little coding example to get the feeling of Unit Testing using JUnit, EasyMock and XMLUnit.
Unit Testing 101 presented at ESRI Developer Summit, March 24th, 2009. This talk reviews the key concepts of unit testing, the technologies used by DTSAgile in out development projects.
A short presentation slide deck I gave to interns we have this summer of 2019 on (unit) testing in software development. This is not a code-centric slide deck and just looking at the slides loses some context without being there in person, or having discussions, etc.
The presentation contains a definition and survey of the benefits of Unit Testing, and a little coding example to get the feeling of Unit Testing using JUnit, EasyMock and XMLUnit.
Unit Testing 101 presented at ESRI Developer Summit, March 24th, 2009. This talk reviews the key concepts of unit testing, the technologies used by DTSAgile in out development projects.
A short presentation slide deck I gave to interns we have this summer of 2019 on (unit) testing in software development. This is not a code-centric slide deck and just looking at the slides loses some context without being there in person, or having discussions, etc.
Common Challenges & Best Practices for TDD on iOSDerek Lee Boire
Presented at the June 2016 Tokyo iOS Meetup on 6/11/2016, in this presentation I give an overview of test driven development and how it can be used when developing for iOS / Swift.
TDD is an enormous topic so this really just scratches the surface to give an expansive glimpse into the journey that TDD truly is. Those unfamiliar with TDD will hopefully have a desire to learn more about it while those familiar will hopefully learn something new.
Software quality is critical to consistently and continually delivering new features to our users. This talk covers the importance of software quality and how to deliver it via unit testing, Test Driven Development and clean code in general.
This is the deck from a talk I gave at Desert Code Camp 2013.
Unit testing has entered the main stream. It is generally considered best practice to have a high level of unit test code coverage, and to ideally write tests before the code, via Test Driven Development.
However, some code is just plain difficult to test. The cost of effort of adding the tests may seem to outweigh the benefits. In this session, we will do a quick review of the benefits of unit tests, but focus on how to test tricky code, such as that static and private methods, and legacy code in general.
Examples are in Java, but the principals are language agnostic.
Getting Unstuck: Working with Legacy Code and DataCory Foy
From this presentation for the IASA in 2007, Cory covers common challenges in dealing with Legacy Code and Data, and some tools and techniques for handling them.
Oplægget blev holdt ved et seminar i InfinIT-interessegruppen Softwaretest den 28. september 2010.
Læs mere om interessegruppen på http://www.infinit.dk/dk/interessegrupper/softwaretest/softwaretest.htm
A brief introduction about the art of unit test, how to test a class, mock a collaborator and use a fake database. TDD is introduced. Code for exercises is available on github along with a detailed explanation. Examples and exercises are written in Java.
San Francisco Software Craftsmanship Meetup
Test Driven Developers Bay Area Meetup
TDD Flow: The Mantra in Action” is a talk + hands-on about the mantra of TDD and its core patterns. Here are some questions for this talk: What is TDD? How to write a good test that fails? How to write code enough to make the test pass? How to remove duplication? How to refactor code? How to create clean code? Is TDD about testing or design? How small should a test be? Should I only write unit tests? Should I estimate TDD? How to use TDD with other agile methods like Scrum, Kanban or BDD? And finally, how to flow in TDD?
Lightening Talk I gave at Inaka in May 2014.
This is sort of the continuation of my previous iOS TDD talk.
Since TDD and DI go quite hand in hand and they are both extend concepts to learn in one shot, I had to prepare a completely separated talk for spreading to my fellows the DI knowledge I had acquired.
Common Challenges & Best Practices for TDD on iOSDerek Lee Boire
Presented at the June 2016 Tokyo iOS Meetup on 6/11/2016, in this presentation I give an overview of test driven development and how it can be used when developing for iOS / Swift.
TDD is an enormous topic so this really just scratches the surface to give an expansive glimpse into the journey that TDD truly is. Those unfamiliar with TDD will hopefully have a desire to learn more about it while those familiar will hopefully learn something new.
Software quality is critical to consistently and continually delivering new features to our users. This talk covers the importance of software quality and how to deliver it via unit testing, Test Driven Development and clean code in general.
This is the deck from a talk I gave at Desert Code Camp 2013.
Unit testing has entered the main stream. It is generally considered best practice to have a high level of unit test code coverage, and to ideally write tests before the code, via Test Driven Development.
However, some code is just plain difficult to test. The cost of effort of adding the tests may seem to outweigh the benefits. In this session, we will do a quick review of the benefits of unit tests, but focus on how to test tricky code, such as that static and private methods, and legacy code in general.
Examples are in Java, but the principals are language agnostic.
Getting Unstuck: Working with Legacy Code and DataCory Foy
From this presentation for the IASA in 2007, Cory covers common challenges in dealing with Legacy Code and Data, and some tools and techniques for handling them.
Oplægget blev holdt ved et seminar i InfinIT-interessegruppen Softwaretest den 28. september 2010.
Læs mere om interessegruppen på http://www.infinit.dk/dk/interessegrupper/softwaretest/softwaretest.htm
A brief introduction about the art of unit test, how to test a class, mock a collaborator and use a fake database. TDD is introduced. Code for exercises is available on github along with a detailed explanation. Examples and exercises are written in Java.
San Francisco Software Craftsmanship Meetup
Test Driven Developers Bay Area Meetup
TDD Flow: The Mantra in Action” is a talk + hands-on about the mantra of TDD and its core patterns. Here are some questions for this talk: What is TDD? How to write a good test that fails? How to write code enough to make the test pass? How to remove duplication? How to refactor code? How to create clean code? Is TDD about testing or design? How small should a test be? Should I only write unit tests? Should I estimate TDD? How to use TDD with other agile methods like Scrum, Kanban or BDD? And finally, how to flow in TDD?
Lightening Talk I gave at Inaka in May 2014.
This is sort of the continuation of my previous iOS TDD talk.
Since TDD and DI go quite hand in hand and they are both extend concepts to learn in one shot, I had to prepare a completely separated talk for spreading to my fellows the DI knowledge I had acquired.
An introduction to code refactoring, the process of restructuring existing computer code without changing its external behavior. This keynote will also include common techniques of doing code refactoring, with real-code demonstration.
Lets break some code. In this workshop we will be going over some of the fundamental concepts of software testing and take a hands on approach to writing Unit and Integration tests. We will cover topics such as mocking, stubbing, database patching and how this can all fit into a continuous integration environment like Jenkins.
Test Automation - Principles and PracticesAnand Bagmar
Slides from my webinar for Sri Lanka Testing Community on - "Test Automation - Principles & Practices".
Details about the webinar can be found from my blog - http://essenceoftesting.blogspot.com
TDD is the elengant way of designing software. People scares from it so much, because software design is hard and it requires discipline. In this talk, I tried to describe what TDD is from software design perspective.
This was a workshop given on the UTN University, for the Software Engineering students. The idea is to give a brief explanation about TDD, and how to use it.
Unit tests give developers and testers a quick way to look for logic errors in the methods of classes in Visual C#, Visual Basic, and Visual C++ projects. A unit test can be created one time and run every time that source code is changed to make sure that no bugs are introduced.
Implementing TDD in for .net Core applicationsAhmad Kazemi
This is a presentation I made to make decision on which tools and frameworks should we use in our new dotnet core application to implement test driven development.
Clean code is subjective and every developer has a personal take on it. There are some ideas that are considered best practice and what constitutes clean code within the industry and community, but there is no definitive distinction.
This page provides a brief overview of testing Mule, linking testing concepts to the tools available to test your Mule applications, as well as to more in-depth pages detailing each concept.
2. Unit Testing Purpose
Proof that our classes work properly
If we repaired the bug in the code, we
would like to be sure it won’t happen again
Isolate each part of the program and show that
the individual parts are correct.
3. Encourages programmers to make
changes to the code since it is easy for
the programmer to check if the piece is
still working properly.
Unit testing allows the programmer to re-factor code
and make sure the module still works correctly (i.e.
regression testing).
Unit Testing Purpose
4. If we did break something, we would like to know about it ASAP
and not wait until QA finds the bug for us
the sooner a bug is detected, the simpler and less costly it is to fix
If we break something we would like to know how it
worked originally; unit testing provides a sort of "living
document".
Unit Testing Purpose
5. Enforce higher quality code because of SOLID,
CLEAN code and OOP principles that is
necessary for successful unit test creation.
This results in loosely coupled code, minimized
dependencies in the system, etc.
Unit Testing Purpose
6. Unit-testing will not catch every error in the program.
It will not catch integration errors
It will not catch performance problems
It will not catch system-wide issues.
Disadvantages
Not all code may be covered with Unit
Tests. For example if class has tight
coupled instances
7. Disadvantages
Aa a supplement to development, additional time
required for implementation and support of unit
test.
9. TDD Disadvantages
Big time investment, additional complexity,
architecture impact, much more thinking ;)
Shallow (long) Learning Curve
10. ReSharper
• Save time on compilation, locating & fixing errors – ReSharper
instantly detects and highlights errors in your code and allows
automatic corrections for most errors – much less possibilities
for bugs
Example:
11. ReSharper
• Automate routine tasks – Quickly create methods,
properties, variables or classes from their usages, generate
constructors, properties, delegating and equality members;
implement and override members; and much more
Example:
12. ReSharper
• Get useful hints right when you need them – IntelliSense,
including code completion and quick parameter information
Example:
13. ReSharper
• Improve your coding practices – Change is easy — with
solution-wide, cross-language refactorings (nearly 6 times as
many as in Microsoft Visual Studio, and growing), additional
automated code transformations, and code cleanup Example:
14. ReSharper
• Navigate to any corner of your solution – Reach any part of
your code within seconds, with dozens of smart navigation
and search features
Example:
15. ReSharper
• Handle multi-language solutions with ease – Refactorings,
navigation and search, and coding assistance work across
C#, VB.NET, XAML, ASP.NET, TypeScript, JavaScript, CSS and
more languages – Support all languages in the same
solution – CSLP – TypeScript / HTML / C# / JavaScript
Example:
16. ReSharper
• ReSharper provides a unit test runner that helps you
run and debug unit tests based on NUnit, xUnit.net,
MSTest, QUnit and Jasmine. You can explore tests,
group them in different ways, break them down into
individual sessions, see test output and navigate to
source code from stack traces.
17. ReSharper
• Analyzing code coverage with dotCover
• You can easily discover the degree to which the code
of your solution is covered with unit tests.
18. ReSharper
• For those who are working with Visual Studio Code
have to use TSLint plugin to review, analyze code
• TSLint checks your TypeScript code for readability,
maintainability, and functionality errors.
Example:
19. Examples of when you should refactor the code before creating unit tests
Tested Method / Class (Unit) has more than one responsibility
Private Class / Methods.
(Possible with using reflection, but will significantly reduce the performance of
tests)
Method / Class don’t allow dependency injection,
for example tightly coupled instances [new
object();]
20. All dependencies are explicitly passed in constructor/method parameters or properties. If it is not
passed, it should not be used.
Must avoid hidden dependencies
Static methods (like DateTime.Now)
Singletons
21. OOD, CLEAN Code and SOLID Principles
OOD principles we must use in order to get testable application
Encapsulation
• Hide methods / properties…but REMEMBER private objects
shouldn't be tested
Abstraction
• Domain analysis
• Legacy analysis
• Levels of abstraction
Inheritance
• Interfaces not concretes
• Code reuse
Polymorphism
22. S.O.L.I.D. - Five basic principles of object-oriented
programming and design. The principles, when applied
together, intend to make it more likely that a
programmer will create a system that is easy
to maintain and extend over time. The principles of SOLID
are guidelines that can be applied while working on
software to remove code smells by causing the
programmer to refactor the software's source code until it
is both legible and extensible.
23. OOD, CLEAN Code and SOLID Principles
Single responsibility principle - a class should have only a single responsibility
Makes clear the purpose of each class, increases maintainability, and
promotes code reuse
24. OOD, CLEAN Code and SOLID Principles
Open / closed principle – should be open for extension, but closed for modification
increases the maintainability and reusability of code
If you will add new functionality, create a new class extending an existing one, rather than changing it
25. OOD, CLEAN Code and SOLID Principles
Liskov substitution principle - objects in a program should be replaceable with instances of their
subtypes without altering the correctness of that program - It gives us Code reuse
If you create a new class extending an existing class, make sure it's completely interchangeable with its base
27. OOD, CLEAN Code and SOLID Principles
Dependency Inversion Principle - Dependency Injection provides a means of injecting
dependencies into an object as opposed to hard coding the dependencies within the object
itself. Classes designed in this matter lend themselves to both unit testing via mocking or
stubbing
35. Most of the unit tests requires using of MOCK objects. For example if you have provider to test
and you don’t have connection any time you run the test or you don’t want to be depend on the
connection. In order to create MOCK object we must use interface. We can create stub objects
instead of mock – reduce performance, much more complicated and serves just for state not
behaviour (cant return results)
Unit Tests with Mocks
Depend upon Abstractions. Do not depend upon concretions.
36. Providing SUT with Mocking, Faking, Stubbing
Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists.
Fake objects actually have working implementations, but usually take some shortcut which makes them not
suitable for production (an in memory database is a good example).
Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside
what's programmed in for the test. Stubs may also record information about calls.
Mocks are what we are talking about here: objects pre-programmed with expectations
which form a specification of the calls they are expected to receive.
37. Providing SUT with Mocking, Faking, Stubbing
Creating Mock Object
• The first step – create data on the mocking (properties,
etc.)
• The second step - create expectations on the mock
object. The expectations indicate which methods
should be called on the mocks when the SUT is
exercised.
43. Mocking Objects https://github.com/Moq/moq4
Mocking is an integral part of unit testing. Although you can run your unit tests without
use of mocking but it will drastically slow down the executing time of unit tests and also
will be dependent on external resources.
The mock object knows in advance what is supposed to happen during the test (e.g. which
of its methods calls will be invoked, etc.) and the mock object knows how it is supposed to
react (e.g. what return value to provide). The mock will indicate whether what really
happens differs from what is supposed to happen. A custom mock object could be coded
for the expected behavior of each test case (see example)
In some cases we can use FAKE or STUB objects instead of Mock. For example concrete class don’t have an
interface and we can’t mock this object. So we can create FAKE object and use it for testing. In this case we will
dramatically reduce test performance and FAKE object has MUCH more less possibilities for testing.
Mock objects are simulated objects that mimic the behavior of real objects in controlled ways.