This document discusses principles and practices for unit testing legacy code. It covers background on large, old software projects with complex code. The motivation is to facilitate changes, not find bugs. Principles include keeping tests simple, not adding tests to bad code, avoiding assumptions, stopping legacy code creation, and educating others. Practices include setting up a framework, domain modeling, identifying hot areas to start, using a bottom-up approach, learning functions through tests, and making code testable by refactoring dependencies. The document advocates bringing order to chaos and finding fun in learning features and deleting code.
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.
The document provides an overview of test-driven development (TDD), including:
1. TDD follows a basic workflow of writing a failing test first, then code to pass the test, and refactoring.
2. TDD is not a replacement for high-level design or frameworks, as it is bottom-up and doesn't provide a big picture view.
3. Unit tests are a tool used in TDD to drive design and ensure correctness, but other types of tests are also needed.
This document discusses PIT, a tool for mutation testing Java code. PIT works by making small changes to the code called mutants, running existing tests against these mutants, and seeing if any tests fail. If a test fails on a mutant, it means that test is effective at finding that type of error. PIT can help evaluate test coverage and quality by exposing weaknesses. It is fast and can test hundreds of thousands of mutants in under a second. PIT can be used for personal code quality or integrated into build/CI pipelines. Alternatives to PIT include Jester and Jumble.
The document provides best practices for writing unit tests, including mocking external services, writing focused tests for individual code units, avoiding unnecessary assertions, using annotations to test exceptions, and refactoring code if tests become too complex. Good practices like giving tests descriptive names and adding new tests for each found bug are also recommended. The document emphasizes that tests should serve as documentation and prevent regressions.
The Spock unit testing framework is on the verge of a 1.0 release and has already proven itself to be the next generation thinking on how to test Java production code. One of the many ever present challenges to testing code is the ability to Mock classes which has simplified by Spock from a very early release. Recently added to Spock is the notion of Stubs and Spies. This sessions is designed to demonstrate proper unit testing technique showing off these new features along with a number of advanced Spock features.
Pitfalls Of Tdd Adoption by Bartosz BankowskiAgileee
This document discusses test-driven development (TDD) and provides best practices for writing tests using a TDD approach. It begins with an introduction to TDD and why organizations adopt it. It then discusses the author's experience teaching and implementing TDD. The main body provides guidance on what to test, how to structure tests, and pitfalls to avoid, such as bloated fixtures, noisy fixtures, unstable test data, and verifying multiple behaviors in one test. It concludes by emphasizing the importance of training, code reviews, and references additional resources to learn more about TDD.
This document discusses improving server-side unit testing methods. It identifies issues with current server unit tests such as dependencies between classes and lack of clear purpose or expectations. It recommends defining a "unit" as a single Java class and mocking dependencies. Tests should describe specifications, improve code quality, and reduce bugs. While DRY principles are best for production code, DAMP (Descriptive And Meaningful Phrases) is preferable for unit tests to prioritize readability over code duplication. Each test should focus on one thing, use plain language, and assert expected outcomes rather than null values.
This document discusses principles and practices for unit testing legacy code. It covers background on large, old software projects with complex code. The motivation is to facilitate changes, not find bugs. Principles include keeping tests simple, not adding tests to bad code, avoiding assumptions, stopping legacy code creation, and educating others. Practices include setting up a framework, domain modeling, identifying hot areas to start, using a bottom-up approach, learning functions through tests, and making code testable by refactoring dependencies. The document advocates bringing order to chaos and finding fun in learning features and deleting code.
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.
The document provides an overview of test-driven development (TDD), including:
1. TDD follows a basic workflow of writing a failing test first, then code to pass the test, and refactoring.
2. TDD is not a replacement for high-level design or frameworks, as it is bottom-up and doesn't provide a big picture view.
3. Unit tests are a tool used in TDD to drive design and ensure correctness, but other types of tests are also needed.
This document discusses PIT, a tool for mutation testing Java code. PIT works by making small changes to the code called mutants, running existing tests against these mutants, and seeing if any tests fail. If a test fails on a mutant, it means that test is effective at finding that type of error. PIT can help evaluate test coverage and quality by exposing weaknesses. It is fast and can test hundreds of thousands of mutants in under a second. PIT can be used for personal code quality or integrated into build/CI pipelines. Alternatives to PIT include Jester and Jumble.
The document provides best practices for writing unit tests, including mocking external services, writing focused tests for individual code units, avoiding unnecessary assertions, using annotations to test exceptions, and refactoring code if tests become too complex. Good practices like giving tests descriptive names and adding new tests for each found bug are also recommended. The document emphasizes that tests should serve as documentation and prevent regressions.
The Spock unit testing framework is on the verge of a 1.0 release and has already proven itself to be the next generation thinking on how to test Java production code. One of the many ever present challenges to testing code is the ability to Mock classes which has simplified by Spock from a very early release. Recently added to Spock is the notion of Stubs and Spies. This sessions is designed to demonstrate proper unit testing technique showing off these new features along with a number of advanced Spock features.
Pitfalls Of Tdd Adoption by Bartosz BankowskiAgileee
This document discusses test-driven development (TDD) and provides best practices for writing tests using a TDD approach. It begins with an introduction to TDD and why organizations adopt it. It then discusses the author's experience teaching and implementing TDD. The main body provides guidance on what to test, how to structure tests, and pitfalls to avoid, such as bloated fixtures, noisy fixtures, unstable test data, and verifying multiple behaviors in one test. It concludes by emphasizing the importance of training, code reviews, and references additional resources to learn more about TDD.
This document discusses improving server-side unit testing methods. It identifies issues with current server unit tests such as dependencies between classes and lack of clear purpose or expectations. It recommends defining a "unit" as a single Java class and mocking dependencies. Tests should describe specifications, improve code quality, and reduce bugs. While DRY principles are best for production code, DAMP (Descriptive And Meaningful Phrases) is preferable for unit tests to prioritize readability over code duplication. Each test should focus on one thing, use plain language, and assert expected outcomes rather than null values.
The document discusses unit testing and best practices for writing effective unit tests. It defines what a unit test is and explores different philosophies for testing. It addresses challenges like flaky tests, testing private methods, and relying too heavily on code coverage metrics. The document provides examples of how to avoid these issues and write clean, focused unit tests that reliably test single units of code.
The document discusses unit testing fundamentals, including definitions of unit testing, benefits of unit testing like fewer bugs, and differences between unit and functional testing. It provides best practices for unit testing like tests running fast and in isolation. The document also covers test-driven development, exposing seams to make code testable, using mocking frameworks, and maintaining good test coverage.
Refactoring legacy code driven by tests - ENGLuca Minudel
re you working on code poorly designed or on legacy code that’s hard to test? And you cannot refactor it because there are no tests?
During this Coding Dojo you’ll be assigned a coding challenge in Java, C#, Ruby, JavaScript or Python. You will face the challenge of improving the design and refactoring existing code in order to make it testable and to write unit tests.
We will discuss SOLID principles, the relation between design and TDD, and how this applies to your solution.
Reading list:
Growing Object-Oriented Software, Guided by Tests; Steve Freeman, Nat Pryce
Test Driven Development: By Example; Kent Beck
Working Effectively with Legacy; Michael Feathers
Agile Software Development, Principles, Patterns, and Practices; Robert C. Martin (C++, Java)
Agile Principles, Patterns, and Practices in C#; Robert C. Martin (C#)
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.
Want to know the case for Test-Driven Development? Want to know style tips and gotchas for Testing and TDD? Let Alex Chaffee, former Mad Scientist at Pivotal Labs, tell you everything you didn't know you didn't know about testing.
Unit Testing Concepts and Best PracticesDerek Smith
Unit testing involves writing code to test individual units or components of an application to ensure they perform as expected. The document discusses best practices for unit testing including writing atomic, consistent, self-descriptive tests with clear assertions. Tests should be separated by business module and type and not include conditional logic, loops, or exception handling. Production code should be isolated from test code. The goal of unit testing is to validate that code meets specifications and prevents regressions over time.
Into The Box 2018 | Assert control over your legacy applicationsOrtus Solutions, Corp
This document discusses how to add tests to legacy code using the TestBox testing framework for ColdFusion applications. It defines unit testing and different types of tests like unit, integration, and end-to-end tests. TestBox allows writing automated tests for ColdFusion code and isolating dependencies using test doubles. The document outlines best practices for test-driven development including writing tests before code, using life cycle methods, and refactoring code without changing external behavior. Implementing a testing framework like TestBox helps assert control over legacy applications by adding tests and the ability to refactor code safely.
This document discusses best practices for unit testing. It addresses common issues like tests that run slowly, are hard to understand, or test the same thing repeatedly. It provides solutions such as grouping test files by criteria and naming conventions to make tests self-documenting. It advises against over-complex mocks and duplicated logic in tests. Tests should be written clearly so others can easily understand what is being tested when debugging or refactoring code. The key messages are to keep tests focused on specific units, refactor tests that become confusing, and make tests self-explanatory through naming and comments.
VT.NET 20160411: An Intro to Test Driven Development (TDD)Rob Hale
This document provides an introduction to test-driven development (TDD). It discusses the benefits of unit testing over end-to-end testing, including error localization, execution time, tighter feedback loops, and test coverage. It defines what constitutes a unit test and what does not. Examples of difficult scenarios to unit test are given. The basic TDD cycle of writing a failing test, making the test pass, and refactoring is explained. An exercise demonstrates applying TDD principles. Mock objects and the differences between the Chicago and London schools of TDD are briefly covered. Finally, additional resources on TDD are listed.
The document discusses the concept of premature optimization and how it can be counterproductive. It defines optimization as procedures used to make a system as effective as possible, especially mathematical techniques. While optimization is important, prematurely optimizing code before identifying bottlenecks can introduce bugs, waste time, and negatively impact design. The document recommends optimizing during design when possible and only optimizing code proven to be bottlenecks based on measurements. Premature optimization is identified as an anti-pattern that should generally be avoided 97% of the time.
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove
Roy Osherove provides training courses on topics like test-driven development (TDD), behavior-driven development (BDD), and consulting/coaching services. He discusses test reviews as an alternative to code reviews that can be quicker and help learning teams. The presentation focuses on creating tests that are trustworthy, maintainable, and readable through techniques like avoiding test logic, not repeating production logic, separating unit and integration tests, and using readable structures, naming, and avoiding magic values.
This document provides an overview of unit testing and isolation frameworks. It defines key concepts like units, unit tests, stubs, mocks and isolation frameworks. It explains that the goal of unit tests is to test individual units of code in isolation by replacing dependencies with stubs or mocks. It also discusses different isolation frameworks like Rhino Mocks and Moq that make it easier to dynamically create stubs and mocks without writing implementation code. The document covers different styles of isolation like record-and-replay and arrange-act-assert. It emphasizes best practices like having one mock per test and using stubs for other dependencies being tested.
This document discusses test driven development and unit testing. It begins with an agenda that includes the importance of unit testing, test driven development techniques, and unit testing in .NET and Eclipse. It then covers topics like the definition of a unit, myths about unit testing, how test driven development works in short cycles, and metrics for test usage. Finally, it discusses techniques like common test patterns, using mock objects, and unit testing frameworks like NUnit, MSTest, Moq and features in Visual Studio and Eclipse.
Roy Osherove provides training courses on test-driven development (TDD), behavior-driven development (BDD), and consulting/coaching services. He teaches TDD techniques for JavaScript, Ruby, Java, C#, and EpiServer/MVC frameworks. He also offers leadership training through 5whys.com. His focus is on using TDD to drive development, influence design decisions, and enable incremental delivery and early feedback. He advocates for TDD when code will need to be maintained long-term or for minimum viable products, but not for proofs of concept or short-lived code.
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.
This document discusses unit testing, including why testing is important, how to begin unit testing, asynchronous testing, and performance testing. It provides an overview of using XCTest to write unit tests in Xcode, including test targets, running and viewing test results. It covers writing asynchronous tests using expectations and measuring performance using the measureBlock method. The document recommends setting baselines and standard deviations for performance tests and provides references for learning more about unit and UI testing.
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.
This workshop is about testing the right way. Get a clear view on how to test your code in an efficient and useful way!
This first testing-related workshop is about all aspects of unit testing. Integration testing and TDD will have their own dedicated workshops.
The document discusses when and how to include database access in automated tests, providing alternatives like using mock objects or resetting test data. It demonstrates techniques for resetting test databases using tools like DbUnit or transaction rollbacks. The main considerations are balancing test speed versus fully testing database interactions while maintaining independent, repeatable tests.
The document discusses unit testing and best practices for writing effective unit tests. It defines what a unit test is and explores different philosophies for testing. It addresses challenges like flaky tests, testing private methods, and relying too heavily on code coverage metrics. The document provides examples of how to avoid these issues and write clean, focused unit tests that reliably test single units of code.
The document discusses unit testing fundamentals, including definitions of unit testing, benefits of unit testing like fewer bugs, and differences between unit and functional testing. It provides best practices for unit testing like tests running fast and in isolation. The document also covers test-driven development, exposing seams to make code testable, using mocking frameworks, and maintaining good test coverage.
Refactoring legacy code driven by tests - ENGLuca Minudel
re you working on code poorly designed or on legacy code that’s hard to test? And you cannot refactor it because there are no tests?
During this Coding Dojo you’ll be assigned a coding challenge in Java, C#, Ruby, JavaScript or Python. You will face the challenge of improving the design and refactoring existing code in order to make it testable and to write unit tests.
We will discuss SOLID principles, the relation between design and TDD, and how this applies to your solution.
Reading list:
Growing Object-Oriented Software, Guided by Tests; Steve Freeman, Nat Pryce
Test Driven Development: By Example; Kent Beck
Working Effectively with Legacy; Michael Feathers
Agile Software Development, Principles, Patterns, and Practices; Robert C. Martin (C++, Java)
Agile Principles, Patterns, and Practices in C#; Robert C. Martin (C#)
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.
Want to know the case for Test-Driven Development? Want to know style tips and gotchas for Testing and TDD? Let Alex Chaffee, former Mad Scientist at Pivotal Labs, tell you everything you didn't know you didn't know about testing.
Unit Testing Concepts and Best PracticesDerek Smith
Unit testing involves writing code to test individual units or components of an application to ensure they perform as expected. The document discusses best practices for unit testing including writing atomic, consistent, self-descriptive tests with clear assertions. Tests should be separated by business module and type and not include conditional logic, loops, or exception handling. Production code should be isolated from test code. The goal of unit testing is to validate that code meets specifications and prevents regressions over time.
Into The Box 2018 | Assert control over your legacy applicationsOrtus Solutions, Corp
This document discusses how to add tests to legacy code using the TestBox testing framework for ColdFusion applications. It defines unit testing and different types of tests like unit, integration, and end-to-end tests. TestBox allows writing automated tests for ColdFusion code and isolating dependencies using test doubles. The document outlines best practices for test-driven development including writing tests before code, using life cycle methods, and refactoring code without changing external behavior. Implementing a testing framework like TestBox helps assert control over legacy applications by adding tests and the ability to refactor code safely.
This document discusses best practices for unit testing. It addresses common issues like tests that run slowly, are hard to understand, or test the same thing repeatedly. It provides solutions such as grouping test files by criteria and naming conventions to make tests self-documenting. It advises against over-complex mocks and duplicated logic in tests. Tests should be written clearly so others can easily understand what is being tested when debugging or refactoring code. The key messages are to keep tests focused on specific units, refactor tests that become confusing, and make tests self-explanatory through naming and comments.
VT.NET 20160411: An Intro to Test Driven Development (TDD)Rob Hale
This document provides an introduction to test-driven development (TDD). It discusses the benefits of unit testing over end-to-end testing, including error localization, execution time, tighter feedback loops, and test coverage. It defines what constitutes a unit test and what does not. Examples of difficult scenarios to unit test are given. The basic TDD cycle of writing a failing test, making the test pass, and refactoring is explained. An exercise demonstrates applying TDD principles. Mock objects and the differences between the Chicago and London schools of TDD are briefly covered. Finally, additional resources on TDD are listed.
The document discusses the concept of premature optimization and how it can be counterproductive. It defines optimization as procedures used to make a system as effective as possible, especially mathematical techniques. While optimization is important, prematurely optimizing code before identifying bottlenecks can introduce bugs, waste time, and negatively impact design. The document recommends optimizing during design when possible and only optimizing code proven to be bottlenecks based on measurements. Premature optimization is identified as an anti-pattern that should generally be avoided 97% of the time.
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove
Roy Osherove provides training courses on topics like test-driven development (TDD), behavior-driven development (BDD), and consulting/coaching services. He discusses test reviews as an alternative to code reviews that can be quicker and help learning teams. The presentation focuses on creating tests that are trustworthy, maintainable, and readable through techniques like avoiding test logic, not repeating production logic, separating unit and integration tests, and using readable structures, naming, and avoiding magic values.
This document provides an overview of unit testing and isolation frameworks. It defines key concepts like units, unit tests, stubs, mocks and isolation frameworks. It explains that the goal of unit tests is to test individual units of code in isolation by replacing dependencies with stubs or mocks. It also discusses different isolation frameworks like Rhino Mocks and Moq that make it easier to dynamically create stubs and mocks without writing implementation code. The document covers different styles of isolation like record-and-replay and arrange-act-assert. It emphasizes best practices like having one mock per test and using stubs for other dependencies being tested.
This document discusses test driven development and unit testing. It begins with an agenda that includes the importance of unit testing, test driven development techniques, and unit testing in .NET and Eclipse. It then covers topics like the definition of a unit, myths about unit testing, how test driven development works in short cycles, and metrics for test usage. Finally, it discusses techniques like common test patterns, using mock objects, and unit testing frameworks like NUnit, MSTest, Moq and features in Visual Studio and Eclipse.
Roy Osherove provides training courses on test-driven development (TDD), behavior-driven development (BDD), and consulting/coaching services. He teaches TDD techniques for JavaScript, Ruby, Java, C#, and EpiServer/MVC frameworks. He also offers leadership training through 5whys.com. His focus is on using TDD to drive development, influence design decisions, and enable incremental delivery and early feedback. He advocates for TDD when code will need to be maintained long-term or for minimum viable products, but not for proofs of concept or short-lived code.
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.
This document discusses unit testing, including why testing is important, how to begin unit testing, asynchronous testing, and performance testing. It provides an overview of using XCTest to write unit tests in Xcode, including test targets, running and viewing test results. It covers writing asynchronous tests using expectations and measuring performance using the measureBlock method. The document recommends setting baselines and standard deviations for performance tests and provides references for learning more about unit and UI testing.
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.
This workshop is about testing the right way. Get a clear view on how to test your code in an efficient and useful way!
This first testing-related workshop is about all aspects of unit testing. Integration testing and TDD will have their own dedicated workshops.
The document discusses when and how to include database access in automated tests, providing alternatives like using mock objects or resetting test data. It demonstrates techniques for resetting test databases using tools like DbUnit or transaction rollbacks. The main considerations are balancing test speed versus fully testing database interactions while maintaining independent, repeatable tests.
Using Rhino Mocks for Effective Unit TestingMike Clement
This document discusses using Rhino Mocks, an isolation and mocking framework, for effective unit testing. It defines different types of test doubles like stubs and mocks, and their purposes. It provides examples of using Rhino Mocks to generate stubs and mocks, set expectations, and verify interactions for more complex unit tests when simple tests are not sufficient. Constraints for matching arguments and properties in expectations are also covered in detail.
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 document discusses effective unit testing. It covers topics like the value of writing tests, test-driven development, behavior-driven development, test doubles, structuring tests with arrange-act-assert/given-when-then, checking behavior not implementation, test smells, JUnit basics, and parameterized testing. The goal of tests is to validate code behavior, catch mistakes, and shape design. Writing tests also helps learn what the code is intended to do.
This document discusses unit testing in iOS. It defines unit testing as small pieces of code that test individual parts of a program to show they are correct. Key advantages are finding problems early, demonstrating code works, and ensuring regressions don't reoccur. The document covers the XCTest framework, writing testable code, mocks and stubs. It provides examples of writing unit tests in Xcode including for asynchronous operations and performance. Continuous integration with Xcode Server is also discussed.
This document provides an introduction to automated testing. It discusses the motivations for automated testing such as improving quality and catching bugs early. It covers basic testing concepts like unit, integration, and system tests. It explains testing principles such as keeping tests independent and focusing on visible behavior. The document also discusses popular testing frameworks for different programming languages and provides examples of tests from a codebase.
This document provides an overview of optimizing stored procedure performance in SQL Server 2000. It discusses the initial processing of stored procedures, including resolution, compilation, optimization and execution. It covers issues that can cause recompilation of stored procedures and different options for handling recompilation. The document also provides best practices for naming conventions, writing solid code to avoid excessive recompilations, and detecting recompilations. It recommends testing recompilation behavior and using modular code and statement recompilation where appropriate. The overview aims to help optimize stored procedure performance.
This document provides an overview of testing concepts and best practices. It discusses different types of bugs, the benefits of writing unit tests, test types like unit tests and integration tests, testability factors, isolation techniques using test doubles, common mistakes to avoid, and Microsoft Fakes for improving testability. The key points covered are:
- The importance of writing tests to prevent bugs and allow safe refactoring.
- Techniques like dependency injection, interfaces, and seams to make code more testable and allow isolation using stubs, fakes, mocks, and shims.
- Common mistakes for test code like testing multiple features in one test, long test runs without maintenance, lack of negative testing, and unclear
The document discusses introductory concepts and best practices for unit testing, including:
1. Why unit tests are important for reducing bugs, improving design, and making development faster.
2. The different types of tests like unit tests, integration tests, and functional tests.
3. What constitutes a unit test, including that it is small, repeatable, consistent, and fast.
4. An example of writing a "Hello World" unit test in C#.
This document provides an overview of unit testing and mocking frameworks. It discusses why we unit test and mock, defines common mocking terminology like mocks, stubs and dummies. It then provides an introduction to the Mockito mocking framework, including its syntax and limitations. Examples are provided to demonstrate mocking with Mockito for a user report generation system.
Ever tried doing Test First Test Driven Development? Ever failed? TDD is not easy to get right. Here's some practical advice on doing BDD and TDD correctly. This presentation attempts to explain to you why, what, and how you should test, tell you about the FIRST principles of tests, the connections of unit testing and the SOLID principles, writing testable code, test doubles, the AAA of unit testing, and some practical ideas about structuring tests.
Writing useful automated tests for the single page applications you buildAndrei Sebastian Cîmpean
How to approach testing if you are building a modern single page application. I try to emphasize that integration testing is the way to go and that developers should consider the tests as part of the system and spend time to maintain them.
Test-driven development (TDD) is a software development process that relies on the repetition of short development cycles called the TDD cycle. The TDD cycle involves first writing a test case that defines a desired improvement or new function, then producing code to pass that test and finally refactoring the new code to acceptable standards. The document discusses TDD training which includes topics like fixtures, assertion patterns, test quality and a case study. It motivates TDD by explaining how it helps build quality code, improves maintainability and meets client needs by focusing on internal and external quality. Key aspects of TDD like the AAA test format and strategies for selecting the next test are also covered. Finally, the document reviews evidence from case
Back-2-Basics: .NET Coding Standards For The Real WorldDavid McCarter
The document provides information about coding standards and best practices for .NET development. It recommends establishing coding standards for organizations to promote consistent and maintainable code. It also discusses specific standards for elements like namespaces, enums, classes, methods, and comments. Examples are provided to illustrate proper naming conventions, formatting, and defensive coding techniques.
Back-2-Basics: .NET Coding Standards For The Real WorldDavid McCarter
This session will guide any level of programmer to greater productivity by providing the information needed to write consistent, maintainable code. Learn about project setup, assembly layout, code style, defensive programming and much, much more. We will even go over some real in production code and see what the programmer did wrong in "What's Wrong With this Code?". Code tips are included to help you write better, error free applications. Lots of code examples in C# and VB.NET.
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentAll Things Open
The document provides an overview of test-driven development (TDD) principles and how to implement testing for front-end development. It discusses the benefits of TDD, such as avoiding bad designs and preventing regressions. It also addresses common challenges with TDD, like slowing initial velocity and ignored tests over time. The document then covers different levels of testing, including unit tests, integration tests, and functional/end-to-end tests using the testing pyramid as a framework. It provides examples of writing tests for pure and impure functions using the Jest testing framework. Finally, it discusses functional testing using Cucumber.js behavior-driven development.
Stopping the Rot - Putting Legacy C++ Under TestSeb Rose
The document discusses introducing unit testing to legacy C++ code. It covers choosing a testing framework, writing initial tests and mocks, and various refactoring techniques like wrapping dependencies, extracting components, and adding non-intrusive C seams to facilitate testing. The goal is to incrementally make the code more testable while maintaining functionality through practices like test-driven development.
1. The document discusses techniques for testing legacy production code that was not originally written with testability in mind. This includes unit testing, which allows verifying code works as expected in isolation, and writing tests before making changes to help preserve existing behavior.
2. Testing legacy code can be challenging as the code may have dependencies that are hard to isolate for testing purposes. Techniques to address this include extracting functions to new classes, replacing static dependencies with interfaces, and overriding classes to inject test dependencies.
3. While testing legacy code requires more initial work, it provides long-term benefits like reducing defects, empowering refactoring, and creating a safety net for future changes. The document provides a case study and
The document provides a biography and background information on Daniel N. Egan, including his roles as a Microsoft Regional Director, Microsoft MVP for ASP.Net, author, and speaker. It then outlines the topics to be covered in the presentation, including object relational mappers, language enhancements in C# and VB.Net, LINQ goals, fundamentals and usage.
Design and optimization of ion propulsion dronebjmsejournal
Electric propulsion technology is widely used in many kinds of vehicles in recent years, and aircrafts are no exception. Technically, UAVs are electrically propelled but tend to produce a significant amount of noise and vibrations. Ion propulsion technology for drones is a potential solution to this problem. Ion propulsion technology is proven to be feasible in the earth’s atmosphere. The study presented in this article shows the design of EHD thrusters and power supply for ion propulsion drones along with performance optimization of high-voltage power supply for endurance in earth’s atmosphere.
Software Engineering and Project Management - Introduction, Modeling Concepts...Prakhyath Rai
Introduction, Modeling Concepts and Class Modeling: What is Object orientation? What is OO development? OO Themes; Evidence for usefulness of OO development; OO modeling history. Modeling
as Design technique: Modeling, abstraction, The Three models. Class Modeling: Object and Class Concept, Link and associations concepts, Generalization and Inheritance, A sample class model, Navigation of class models, and UML diagrams
Building the Analysis Models: Requirement Analysis, Analysis Model Approaches, Data modeling Concepts, Object Oriented Analysis, Scenario-Based Modeling, Flow-Oriented Modeling, class Based Modeling, Creating a Behavioral Model.
Advanced control scheme of doubly fed induction generator for wind turbine us...IJECEIAES
This paper describes a speed control device for generating electrical energy on an electricity network based on the doubly fed induction generator (DFIG) used for wind power conversion systems. At first, a double-fed induction generator model was constructed. A control law is formulated to govern the flow of energy between the stator of a DFIG and the energy network using three types of controllers: proportional integral (PI), sliding mode controller (SMC) and second order sliding mode controller (SOSMC). Their different results in terms of power reference tracking, reaction to unexpected speed fluctuations, sensitivity to perturbations, and resilience against machine parameter alterations are compared. MATLAB/Simulink was used to conduct the simulations for the preceding study. Multiple simulations have shown very satisfying results, and the investigations demonstrate the efficacy and power-enhancing capabilities of the suggested control system.
An improved modulation technique suitable for a three level flying capacitor ...IJECEIAES
This research paper introduces an innovative modulation technique for controlling a 3-level flying capacitor multilevel inverter (FCMLI), aiming to streamline the modulation process in contrast to conventional methods. The proposed
simplified modulation technique paves the way for more straightforward and
efficient control of multilevel inverters, enabling their widespread adoption and
integration into modern power electronic systems. Through the amalgamation of
sinusoidal pulse width modulation (SPWM) with a high-frequency square wave
pulse, this controlling technique attains energy equilibrium across the coupling
capacitor. The modulation scheme incorporates a simplified switching pattern
and a decreased count of voltage references, thereby simplifying the control
algorithm.
Null Bangalore | Pentesters Approach to AWS IAMDivyanshu
#Abstract:
- Learn more about the real-world methods for auditing AWS IAM (Identity and Access Management) as a pentester. So let us proceed with a brief discussion of IAM as well as some typical misconfigurations and their potential exploits in order to reinforce the understanding of IAM security best practices.
- Gain actionable insights into AWS IAM policies and roles, using hands on approach.
#Prerequisites:
- Basic understanding of AWS services and architecture
- Familiarity with cloud security concepts
- Experience using the AWS Management Console or AWS CLI.
- For hands on lab create account on [killercoda.com](https://killercoda.com/cloudsecurity-scenario/)
# Scenario Covered:
- Basics of IAM in AWS
- Implementing IAM Policies with Least Privilege to Manage S3 Bucket
- Objective: Create an S3 bucket with least privilege IAM policy and validate access.
- Steps:
- Create S3 bucket.
- Attach least privilege policy to IAM user.
- Validate access.
- Exploiting IAM PassRole Misconfiguration
-Allows a user to pass a specific IAM role to an AWS service (ec2), typically used for service access delegation. Then exploit PassRole Misconfiguration granting unauthorized access to sensitive resources.
- Objective: Demonstrate how a PassRole misconfiguration can grant unauthorized access.
- Steps:
- Allow user to pass IAM role to EC2.
- Exploit misconfiguration for unauthorized access.
- Access sensitive resources.
- Exploiting IAM AssumeRole Misconfiguration with Overly Permissive Role
- An overly permissive IAM role configuration can lead to privilege escalation by creating a role with administrative privileges and allow a user to assume this role.
- Objective: Show how overly permissive IAM roles can lead to privilege escalation.
- Steps:
- Create role with administrative privileges.
- Allow user to assume the role.
- Perform administrative actions.
- Differentiation between PassRole vs AssumeRole
Try at [killercoda.com](https://killercoda.com/cloudsecurity-scenario/)
Batteries -Introduction – Types of Batteries – discharging and charging of battery - characteristics of battery –battery rating- various tests on battery- – Primary battery: silver button cell- Secondary battery :Ni-Cd battery-modern battery: lithium ion battery-maintenance of batteries-choices of batteries for electric vehicle applications.
Fuel Cells: Introduction- importance and classification of fuel cells - description, principle, components, applications of fuel cells: H2-O2 fuel cell, alkaline fuel cell, molten carbonate fuel cell and direct methanol fuel cells.
Embedded machine learning-based road conditions and driving behavior monitoringIJECEIAES
Car accident rates have increased in recent years, resulting in losses in human lives, properties, and other financial costs. An embedded machine learning-based system is developed to address this critical issue. The system can monitor road conditions, detect driving patterns, and identify aggressive driving behaviors. The system is based on neural networks trained on a comprehensive dataset of driving events, driving styles, and road conditions. The system effectively detects potential risks and helps mitigate the frequency and impact of accidents. The primary goal is to ensure the safety of drivers and vehicles. Collecting data involved gathering information on three key road events: normal street and normal drive, speed bumps, circular yellow speed bumps, and three aggressive driving actions: sudden start, sudden stop, and sudden entry. The gathered data is processed and analyzed using a machine learning system designed for limited power and memory devices. The developed system resulted in 91.9% accuracy, 93.6% precision, and 92% recall. The achieved inference time on an Arduino Nano 33 BLE Sense with a 32-bit CPU running at 64 MHz is 34 ms and requires 2.6 kB peak RAM and 139.9 kB program flash memory, making it suitable for resource-constrained embedded systems.
Applications of artificial Intelligence in Mechanical Engineering.pdfAtif Razi
Historically, mechanical engineering has relied heavily on human expertise and empirical methods to solve complex problems. With the introduction of computer-aided design (CAD) and finite element analysis (FEA), the field took its first steps towards digitization. These tools allowed engineers to simulate and analyze mechanical systems with greater accuracy and efficiency. However, the sheer volume of data generated by modern engineering systems and the increasing complexity of these systems have necessitated more advanced analytical tools, paving the way for AI.
AI offers the capability to process vast amounts of data, identify patterns, and make predictions with a level of speed and accuracy unattainable by traditional methods. This has profound implications for mechanical engineering, enabling more efficient design processes, predictive maintenance strategies, and optimized manufacturing operations. AI-driven tools can learn from historical data, adapt to new information, and continuously improve their performance, making them invaluable in tackling the multifaceted challenges of modern mechanical engineering.
6. Service Functionality
HTTP
VERB
ENDPOINT DESCRIPTION
GET /hello Returns “Hello World”.
GET /hello/{last-name} Looks up the person with the provided
last name. If the person is known, then
returns Hello {First-name} {Last-name}
GET /weather Returns the current weather conditions
for Manchester. (“raining”…always )
7. Internal Service
Architecture
Controller provides REST endpoints
and deal with HTTP requests and
responses.
Repository interfaces with
the database and take care of
writing and reading data to/from
persistent storage.
Client talks to other APIs, in our
case it fetches JSON via HTTPS
from the darksky.net weather API.
Domain classes capture
our domain model including the
domain logic (which, to be fair, is
quite trivial in our case).
8. Action Time!
Checkout the code @https://gitlab.nonprod.dwpcloud.uk/training-testing/spring-demo-app
Open the project with IntelliJ
Open the README file for further instructions
9. Unit Tests
What is a unit?
Social or solitary tests?
Mocking or stubbing?
10. What is a Unit?
To a certain extent it's a matter of your own definition and it's okay to have no canonical
answer.
11. Social or solitary tests?
Solitary unit tests: tests that stub all the collaborators.
Sociable unit tests: tests that allow talking to real collaborators.
12. Mocking or Stubbing? Test Double
Dummy: objects used to fill parameter lists, but never actually used.
Fake: objects with working implementations, but not suitable for production since they take some
shortcuts (an in-memory-db is a good example).
Stubs: objects that provide a canned answer only to predefined calls, ignoring the rest.
Spies: stubs that also record some information based on how they were called.
Mocks: stubs that throw an exception if they receive a call they don’t except and are checked
during verification to ensure thy got all the calls they were excepting.
13. What to Test?
Do not test trivial code.
Stick to the one test class per production class rule of thumb.
A unit test class should at least test the public interface of the class. Private methods should
generally be considered an implementation detail.
Don't reflect your internal code structure within your unit tests. Test for observable behaviour
instead.
14. But I Really Need to Test This
Private Method
You should take a step back and ask yourself why. Are you violating the Single responsibility principal?
15. Test Structure
not limited to unit tests
Set up the test data (Given/Arrange)
Call your method under test (When/Act)
Assert that the expected results are returned (Then /Assert)
Unfortunately the concept of the test pyramid falls a little short if you take a closer look. Some argue that either the naming or some conceptual aspects of Mike Cohn's test pyramid are not ideal, and I have to agree. From a modern point of view the test pyramid seems overly simplistic and can therefore be misleading.
Still, due to its simplicity the essence of the test pyramid serves as a good rule of thumb when it comes to establishing your own test suite. Your best bet is to remember two things from Cohn's original test pyramid:
Write tests with different granularity
The more high-level you get the fewer tests you should have
In fact they can be quite misleading: service test is a term that is hard to grasp (Cohn himself talks about the observation that a lot of developers completely ignore this layer). In the days of single page application frameworks like react, angular, ember.js and others it becomes apparent that UI tests don't have to be on the highest level of your pyramid - you're perfectly able to unit test your UI in all of these frameworks.
Given the shortcomings of the original names it's totally okay to come up with other names for your test layers, as long as you keep it consistent within your codebase and your team's discussions.
Our microservice provides a REST interface that can be called via HTTP. For some endpoints the service will fetch information from a database. In other cases the service will call an external weather API via HTTP to fetch and display current weather conditions.
The sample application shows traits of a typical microservice. It provides a REST interface, talks to a database and fetches information from a third-party REST service. It's implemented in Spring Boot and should be understandable even if you've never worked with Spring Boot before.
If you're working in a functional language a unit will most likely be a single function. Your unit tests will call a function with different parameters and ensure that it returns the expected values. In an object-oriented language a unit can range from a single method to an entire class.
Some argue that all collaborators (e.g. other classes that are called by your class under test) of your subject under test should be substituted with mocks or stubs to come up with perfect isolation and to avoid side-effects and a complicated test setup. Others argue that only collaborators that are slow or have bigger side effects (e.g. classes that access databases or make network calls) should be stubbed or mocked.
If you have some spare time you can go down the rabbit hole and read more about the pros and cons of the different schools of thought.
At the end of the day it's not important to decide if you go for solitary or sociable unit tests. Writing automated tests is what's important. Personally, I find myself using both approaches all the time. If it becomes awkward to use real collaborators I will use mocks and stubs generously. If I feel like involving the real collaborator gives me more confidence in a test I'll only stub the outermost parts of my service.
A lot of people use the terms Mock and Stub interchangeably. I think it's good to be precise and keep their specific properties in mind. You can use test doubles to replace objects you'd use in production with an implementation that helps you with testing.
In plain words it means that you replace a real thing (e.g. a class, module or function) with a fake version of that thing. The fake version looks and acts like the real thing (answers to the same method calls) but answers with canned responses that you define yourself at the beginning of your unit test.
Using test doubles is not specific to unit testing. More elaborate test doubles can be used to simulate entire parts of your system in a controlled way. However, in unit testing you're most likely to encounter a lot of mocks and stubs (depending of whether you're the sociable or solitary kind of developer), simply because lots of modern languages and libraries make it easy and comfortable to set up mocks and stubs.
The good thing about unit tests is that you can write them for all your production code classes, regardless of their functionality or which layer in your internal structure they belong to. You can unit tests controllers just like you can unit test repositories, domain classes or file readers. Simply stick to the one test class per production class rule of thumb and you're off to a good start.
A unit test class should at least test the public interface of the class. Private methods can't be tested anyways since you simply can't call them from a different test class. Protected or package-private are accessible from a test class (given the package structure of your test class is the same as with the production class) but testing these methods could already go too far.
There's a fine line when it comes to writing unit tests: They should ensure that all your non-trivial code paths are tested (including happy path and edge cases). At the same time they shouldn't be tied to your implementation too closely.
Why's that?
Tests that are too close to the production code quickly become annoying. As soon as you refactor your production code (quick recap: refactoring means changing the internal structure of your code without changing the externally visible behaviour) your unit tests will break.
This way you lose one big benefit of unit tests: acting as a safety net for code changes. You rather become fed up with those stupid tests failing every time you refactor, causing more work than being helpful; and whose idea was this stupid testing stuff anyways?
What do you do instead? Don't reflect your internal code structure within your unit tests. Test for observable behaviour instead. Think about
if I enter values x and y, will the result be z?
instead of
if I enter x and y, will the method call class A first, then call class B and then return the result of class A plus the result of class B?
Private methods should generally be considered an implementation detail. That's why you shouldn't even have the urge to test them.
I often hear opponents of unit testing (or TDD ) arguing that writing unit tests becomes pointless work where you have to test all your methods in order to come up with a high test coverage. They often cite scenarios where an overly eager team lead forced them to write unit tests for getters and setters and all other sorts of trivial code in order to come up with 100% test coverage.
There's so much wrong with that.
Yes, you should test the public interface. More importantly, however, you don't test trivial code. Don't worry, Kent Beck said it's ok. You won't gain anything from testing simple getters or setters or other trivial implementations (e.g. without any conditional logic). Save the time, that's one more meeting you can attend, hooray!
The solution that often works for me is to split the original class into two classes. It often only takes one or two minutes of thinking to find a good way to cut the one big class into two smaller classes with individual responsibility. I move the private method (that I urgently want to test) to the new class and let the old class call the new method. Voilà, my awkward-to-test private method is now public and can be tested easily. On top of that I have improved the structure of my code by adhering to the single responsibility principle.
This pattern can be applied to other, more high-level tests as well. In every case they ensure that your tests remain easy and consistent to read. On top of that tests written with this structure in mind tend to be shorter and more expressive.
Unfortunately, when it comes to Spring's controllers there's a downside to this approach: Spring MVC's controller make heavy use of annotations to declare which paths they're listening on, which HTTP verbs to use, which parameters they parse from the URL path or query params and so on. Simply invoking a controller's method within your unit tests won't test all of these crucial things.