Applied Programming/Testing

From Wikiversity
Jump to navigation Jump to search

This lesson introduces software testing, unit testing, and test-driven development.

Objectives and Skills[edit]

Objectives and skills for this lesson include:

  • Understand software testing, including unit testing, integration testing, system testing, and operational acceptance testing.
  • Create unit tests to meet given requirements.
  • Describe test-driven development.

Readings[edit]

  1. Wikipedia: Software testing
  2. Wikipedia: Unit testing
  3. Wikipedia: Test-driven development

Multimedia[edit]

  1. YouTube: Software Testing Tutorials for Beginners
  2. YouTube: Software Testing Types
  3. YouTube: What is Unit Testing?
  4. YouTube: Python Unit Testing - Pytest Introduction

Examples[edit]

Activities[edit]

  1. Research available test libraries for your selected programming language. Install a library and create a simple test to verify that the library works as expected.
  2. Create unit tests for the program created in the previous lesson. Test each parameter and result so that you have 100% coverage of all processing functions. Test with valid and invalid data, and verify that errors are raised when appropriate.
  3. If your test library supports it, add tests for input and output functions. Test with valid and invalid data.

Lesson Summary[edit]

  • Software testing is an investigation conducted to provide stakeholders with information about the quality of the software product or service under test.[1]
  • Software testing is used in association with verification and validation.[1]
  • Software testing may be considered a part of a software quality assurance (SQA) process.[1]
  • Software testing can be conducted as soon as executable software (even if partially complete) exists.[1]
  • Unit testing refers to tests that verify the functionality of a specific section of code, usually at the function level.[1]
  • Using unit-test as a design specification has one significant advantage over other design methods: The design document can itself be used to verify the implementation.[2]
  • Unit testing lacks some of the accessibility of a diagrammatic specification such as a UML diagram, but it may be generated from the unit test using automated tools.[2]
  • Extreme programming uses the creation of unit test for test-driven development. The developer writes a unit test that exposes either a software requirement or a defect. This test will fail because either the requirement isn't implemented yet, or because it intentionally exposes a defect in the existing code. Then, the developer writes the simplest code to make the test, along with other tests, pass.[2]
  • Extreme programming's thorough unit testing allows simpler and more confident code development and refactoring, simplified code integration, accurate documentation, and more modular designs. [2]
  • Unit Testing frameworks help simplify the process of unit testing because they have been developed for a wide variety of languages. [2]
  • Frameworks include open source solutions such as the various code-driven testing frameworks known collectively as xUnit [2]
  • It is generally possible to perform unit testing without the support of a specific framework by writing client code that exercises the units under test and uses assertions, exception handling, or other controls flow mechanisms to signal failure.[2]
  • The goal of unit testing is to isolate each part of the program and show that the individual parts are correct.[2]
  • Intuitively, one can view a unit as the smallest testable part of an application. In procedural programming, a unit could be an entire module, but it is more commonly an individual function or procedure. In object-oriented programming, a unit is often an entire interface, such as a class, but could be an individual method.[2]
  • Test-driven development (TDD) is used in both extreme programming and scrum.[2]
  • Unit testing will not catch integration errors or broader system-level errors (such as functions performed across multiple units, or non-functional test areas such as performance).[2]
  • Unit testing only shows the presence or absence of particular errors; it cannot prove a complete absence of errors.[2]
  • Software testing is a combinatorial problem. For example, every Boolean decision statement requires at least two tests: one with an outcome of "true" and one with an outcome of "false". As a result, for every line of code written, programmers often need 3 to 5 lines of test code.[2]
  • Unit testing has the difficulty of setting up realistic and useful tests.[2]
  • Unit testing is being developed on a different platform than the one it will eventually run on. The programmer cannot easily run a test program in the actual deployment environment, as with desktop programs.[2]
  • Test-driven development develops software by requiring specific test cases which the software must pass. This should encourage simple designs in new software, but also can be applied to improving and debugging older legacy code. [3]
  • In TDD, the test is written prior to the code. This shifts developer focus to meeting the test requirements before attempting to write the code. [3]
  • A general outline for implementing TDD would include: add a new test, run the test to confirm that it passes/fails as expected, write the code that will be tested, run the tests on the code, refactor the code if needed, and repeat. [3]

Key Terms[edit]

assertion
A statement that a predicate (Boolean-valued function, i.e. a true-false expression) is always true at that point in code execution. It can help a programmer read the code, help a compiler translate it, or help the program detect its own defects.[4]
behavior-driven development
Combines the general techniques and principles of TDD with ideas from domain-driven design and object-oriented analysis and design to provide software development and management teams with shared tools and a shared process to collaborate on software development.[5]
conformance testing
Testing or other activities that determine whether a process, product, or service complies with the requirements of a specification, technical standard, contract, or regulation.[6]
decision problem
A problem that can be posed as a yes-no question of the input values.[7]
formal verification
The act of proving or disproving the correctness of intended algorithms underlying a system with respect to a certain formal specification or property, using formal methods of mathematics.[8]
halting problem
The problem of determining, from a description of an arbitrary computer program and an input, whether the program will finish running (i.e., halt) or continue to run forever.[9]
integration testing
The testing of a group of related modules. It aims at finding interfacing issues between the modules.[10]
manual testing
The process of manually testing software for defects. It requires a tester to play the role of an end user whereby they use most of the application's features to ensure correct behavior.[11]
mocks, fakes, and stubs
Classification between mocks, fakes, and stubs is highly inconsistent across the literature. All three represent a production object in a testing environment by exposing the same interface. In the book The Art of Unit Testing[12] mocks are described as a fake object that helps decide if a test failed or passed by verifying whether an interaction with an object occurred or not. Everything else is defined as a stub. In The Art of Unit Testing, fakes are anything that is not real, which, based on their usage, can be either stubs or mocks.[13]
performance testing
A testing practice performed to determine how a system performs in terms of responsiveness and stability under a workload.[14]
pytest
Code-driven unit testing frameworks for Python based on xUnit[15]
refactoring
a process of restructuring existing computer code without changing its external behavior [16]
regression testing
Re-running functional and non-functional tests to ensure that previously developed and tested software still performs after a change [17]
software testing
An investigation conducted to provide stakeholders with information about the quality of the software product or service under test.[18]
test case
A specification of the inputs, execution conditions, testing procedure, and expected results that define a single test to be executed to achieve a particular software testing objective, such as exercise a particular program path or verify compliance with a specific requirement.[19]
Test-Driven Development (TDD)
A software development process which intends a developer to write a unit test that exposes either a software requirement or a defect[2]
test harnesses or automated test framework
A collection of software and test data configured to test a program unit by running it under varying conditions and monitoring its behavior and outputs. It has two main parts: the test execution engine and the test script repository.[20]
test suite
A collection of test cases that are intended to be used to test a software program to show that it has some specified set of behaviours.[21]
undecidable problem
A decision problem for which it is proved to be impossible to construct an algorithm that always leads to a correct yes-or-no answer.[22]
unit
The smallest testable part of any software or program.[2]
unit testing
A software testing method by which individual units of source code, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine whether they are fit for use.[2]
xUnit
A framework that outsources to another system the graphical rendering of a view for human consumption [23]

See Also[edit]

  1. Dev.To: The Testing Introduction I Wish I Had
  2. YouTube: Python Tutorial: if __name__ == '__main__'
  3. UserSnap: Software Testing Basics
  4. Guru99: What is Software Testing? Introduction, Definition, Basics & Types
  5. Software Testing Material: Seven Principles of Software Testing
  6. Python.org: unittest — Unit testing framework
  7. Technology Conversations: Test Driven Development (TDD): Example Walkthrough (examples are in Java)
  8. What is Software Testing? 7 answers

References[edit]

  1. 1.0 1.1 1.2 1.3 1.4 Wikipedia: Software testing
  2. 2.00 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.10 2.11 2.12 2.13 2.14 2.15 2.16 2.17 Wikipedia: Unit testing
  3. 3.0 3.1 3.2 Wikipedia: Test-driven development
  4. Wikipedia: Assertion (software development)
  5. Wikipedia: Behavior-driven development
  6. Wikipedia: Conformance Testing
  7. Wikipedia: Decision problem
  8. Wikipedia: Formal verification
  9. Wikipedia: Halting problem
  10. https://artoftesting.com/manualTesting/types-of-testing.html
  11. Wikipedia: Manual testing
  12. Osherove, Roy (2009). "Interaction testing with mock objects et seq". The art of unit testing. Manning. ISBN 978-1-933988-27-6.
  13. Wikipedia: Mock_object
  14. Wikipedia: Software performance testing
  15. Wikipedia: List of unit testing frameworks
  16. Wikipedia: Code refactoring
  17. Wikipedia: Regression testing
  18. Wikipedia: Software testing
  19. Wikipedia: Test case
  20. Wikipedia: Test harness
  21. Wikipedia: Test Suite
  22. Wikipedia: Undecidable problem
  23. Wikipedia: xUnit