Software Testing Principles and Alternatives
47 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the purpose of formulating a unit test plan in programming?

  • To ensure the correctness of functionalities in code (correct)
  • To automate the documentation process
  • To improve code readability
  • To determine the programming language to use

Which of the following actions is part of the testing process with MSTest?

  • Optimizing code runtime efficiency
  • Pre-computing expected outputs for tests (correct)
  • Debugging the code before implementation
  • Revising documentation standards

What is a benefit of using data-driven tests in programming?

  • They help identify performance bottlenecks
  • They reduce the need for input validation
  • They allow testing of multiple scenarios with minimal effort (correct)
  • They simplify the code structure drastically

Which aspect can be verified by a method in unit testing?

<p>The correctness of produced output (A)</p> Signup and view all the answers

What is the role of exceptions in unit testing?

<p>To ensure that expected errors are handled correctly (C)</p> Signup and view all the answers

What happens during stack unwinding when an exception is thrown?

<p>Important cleanup methods may not execute. (B)</p> Signup and view all the answers

What does the 'finally' block do in exception handling?

<p>It executes after the 'try' block regardless of an exception. (D)</p> Signup and view all the answers

When is the 'using' statement particularly beneficial?

<p>When allocating resources that need to be disposed of promptly. (C)</p> Signup and view all the answers

Which approach is recommended when expecting unusual or invalid values?

<p>Utilize error codes instead. (B)</p> Signup and view all the answers

What is a potential performance characteristic of code with exceptions?

<p>Code on the non-exceptional path is faster than on the exceptional path. (A)</p> Signup and view all the answers

What happens if there is no exception handler in MethodB for a thrown exception?

<p>Execution will transfer to the nearest catch block in MethodA. (D)</p> Signup and view all the answers

How can cleanup methods be assured execution during exception handling?

<p>By implementing 'finally' or 'using' statements. (A)</p> Signup and view all the answers

What is the significance of having exception handlers in methods?

<p>They allow recovery from errors and manage application flow. (D)</p> Signup and view all the answers

What is the main purpose of a test plan?

<p>To outline the objectives, scope, approach, and schedule of test activities. (C)</p> Signup and view all the answers

Which of the following should NOT be included in a unit test plan?

<p>A marketing strategy for the software being tested. (C)</p> Signup and view all the answers

What is meant by 'expected outcome' in a test plan?

<p>A detailed and specific description of the correct results. (A)</p> Signup and view all the answers

How should the test categories in a unit test plan be characterized?

<p>They should be descriptive and standardized for organization. (D)</p> Signup and view all the answers

What type of data should be included in the 'setup' section of a unit test plan?

<p>Concrete and reproducible input data. (B)</p> Signup and view all the answers

What should the 'status' column in a unit test plan indicate?

<p>Whether the test passed or failed. (D)</p> Signup and view all the answers

To properly organize tests in the test plan, what types of test categories are typically used?

<p>Standardized and descriptive tags like 'Boundary' or 'Regression'. (B)</p> Signup and view all the answers

Why is it important for the expected outcome to be measurable in a test plan?

<p>To ensure that results can be accurately validated against criteria. (D)</p> Signup and view all the answers

What is the primary purpose of MSTest?

<p>To automate the unit testing process (D)</p> Signup and view all the answers

Which attribute is used to indicate that a method is a unit test?

<p>TestMethod (D)</p> Signup and view all the answers

What is indicated by the TestInitialize attribute in MSTest?

<p>A method runs before every test in the class (B)</p> Signup and view all the answers

Which method is used to compare the actual output with the expected output in a unit test?

<p>Assert (B)</p> Signup and view all the answers

What does the DataTestMethod attribute signify in MSTest?

<p>The test will be called multiple times with different inputs (D)</p> Signup and view all the answers

Which attribute allows you to categorize unit tests in MSTest?

<p>TestCategory (A)</p> Signup and view all the answers

What is the role of DataRow in MSTest?

<p>To provide different inputs for a DataTestMethod (B)</p> Signup and view all the answers

What does the Timeout attribute specify in MSTest?

<p>The maximum time a test can run before failing (B)</p> Signup and view all the answers

What is a primary advantage of using exceptions over traditional error handling?

<p>They allow separation of error handling from normal processing. (A)</p> Signup and view all the answers

Which of the following statements is true regarding the use of exceptions?

<p>Code that raises an exception is said to throw the exception. (C)</p> Signup and view all the answers

What complicates the traditional error handling process when dealing with deep call stacks?

<p>It can cause a large amount of error handling code to be introduced. (D)</p> Signup and view all the answers

What are exceptions generally regarded as?

<p>Undesirable events outside the normal behavior of a program. (B)</p> Signup and view all the answers

What is one of the pitfalls of misusing exceptions?

<p>They can lead to performance costs if not managed properly. (D)</p> Signup and view all the answers

What is a feature provided by exception handling specific to C#?

<p>Exception classes inherit from System.Exception. (B)</p> Signup and view all the answers

When exceptions occur, what happens to the call stack?

<p>The call stack is unwound until suitable error handling code is found. (A)</p> Signup and view all the answers

Which of the following is a disadvantage of traditional error handling?

<p>It can lead to clumsy code paths. (D)</p> Signup and view all the answers

What is implied as a benefit of properly using exceptions?

<p>They can enhance performance compared to traditional error handling. (D)</p> Signup and view all the answers

What happens when an exception is thrown in a constructor?

<p>The exception can be handled later in the code flow. (D)</p> Signup and view all the answers

What is the primary focus during the requirement discovery phase of software development?

<p>Collecting user stories from customers (B)</p> Signup and view all the answers

Which of the following statements best describes non-functional requirements?

<p>They define how the system should perform its tasks. (B)</p> Signup and view all the answers

In the analysis phase, what do the identified nouns and verbs represent?

<p>Nouns as classes or attributes and verbs as methods (D)</p> Signup and view all the answers

What should a developer do when deciding on exception handling?

<p>Choose the right kind of exception and include a helpful message (A)</p> Signup and view all the answers

Which phase of the software development life cycle involves delivering the finished system?

<p>Deployment (B)</p> Signup and view all the answers

What is a common goal during the testing phase of software development?

<p>Ensuring the program meets user expectations (A)</p> Signup and view all the answers

What is indicated by the statement '90% of the system’s lifespan will be spent on maintenance'?

<p>Maintaining and evolving the software is crucial and resource-intensive. (B)</p> Signup and view all the answers

What happens during the implementation phase of the software development life cycle?

<p>Source code is written and compiled into executable form. (B)</p> Signup and view all the answers

Flashcards

Exception Handler

A block of code designed to handle exceptions that might occur during the execution of another block of code.

Try Block

A block of code, where the program attempts potential operations that may result in an exception.

Catch Block

A block of code that executes if an exception is caught within the try block.

Stack Unwinding

The process of automatically closing resources and cleaning up when an exception occurs.

Signup and view all the flashcards

Finally Block

A block of code that executes regardless of whether an exception occurred or not within the try block, useful for cleanup operations.

Signup and view all the flashcards

Using Statement

A language construct that ensures resources (like files, database connections) are properly released when the block exits, even if an exception is raised.

Signup and view all the flashcards

Appropriate Use of Exceptions

Exceptions are best for unexpected errors, and error codes are better for anticipated errors or unusual values.

Signup and view all the flashcards

Software Development Life Cycle (SDLC)

A structured process for creating software, including stages like requirement discovery, design, implementation, testing, deployment, and maintenance.

Signup and view all the flashcards

Functional Requirements

What a software system should do.

Signup and view all the flashcards

Non-functional Requirements

How a system should perform, including aspects like performance, security, and usability.

Signup and view all the flashcards

Requirement Discovery

Gathering user needs and turning them into specifications for a software system, using methods like interviews and surveys.

Signup and view all the flashcards

Analysis (SDLC)

The process of understanding user stories to translate them into relevant classes, attributes, and methods within software.

Signup and view all the flashcards

Design (SDLC)

Creating the blueprints for the software system, including class diagrams and interfaces.

Signup and view all the flashcards

Implementation (SDLC)

The stage where the software code is written and compiled.

Signup and view all the flashcards

Testing (SDLC)

Verifying the software meets user expectations and requirements through multiple tests.

Signup and view all the flashcards

Deployment (SDLC)

The process of releasing the finished software system to users.

Signup and view all the flashcards

Maintenance (SDLC)

Fixing bugs, adding new features, and adapting the software to evolving user needs.

Signup and view all the flashcards

ArgumentException

Exception type used when an invalid argument is passed to a method or function.

Signup and view all the flashcards

Test Plan

A document outlining testing objectives, scope, approach, and schedule.

Signup and view all the flashcards

Unit Testing

Testing individual components (units) of a program.

Signup and view all the flashcards

Test Plan (Table)

Table-based document for unit testing, including test number, description, categories, setup, expected outcome, and status.

Signup and view all the flashcards

Test Number

Unique identifier for each test.

Signup and view all the flashcards

Test Description

Brief summary of the test's purpose.

Signup and view all the flashcards

Test Categories

Tags or labels (e.g., Boundary, Invalid, Valid) to categorize tests.

Signup and view all the flashcards

Test Setup

Detailed instructions on test preparation and input data.

Signup and view all the flashcards

Expected Outcome

Specific, detailed description of correct results.

Signup and view all the flashcards

Test Status

Indicates whether a test passed or failed.

Signup and view all the flashcards

MSTest

A Visual Studio unit testing framework enabling automated unit tests.

Signup and view all the flashcards

TestClass Attribute

Marks a class containing MSTest unit tests, allowing the framework to identify and execute them.

Signup and view all the flashcards

TestMethod Attribute

Marks a method as a unit test within the TestClass, causing automated execution by MSTest.

Signup and view all the flashcards

Test Setup

Initializes objects, defines inputs, and sets expectations before a test is run.

Signup and view all the flashcards

Test Execution

The phase where the unit or function under test is run with defined inputs.

Signup and view all the flashcards

Test Assertion

Verifying the actual outcome of a unit test against the expected outcome.

Signup and view all the flashcards

ExpectedException Attribute

Specifies the type of exception expected to be thrown during a unit test.

Signup and view all the flashcards

DataTestMethod Attribute

Indicates a test method must be executed multiple times with different inputs.

Signup and view all the flashcards

DataRow Attribute

Provides input data to a DataTestMethod for each iteration.

Signup and view all the flashcards

Income Tax Function

A function that calculates Australian personal income tax based on a piecewise linear formula.

Signup and view all the flashcards

Unit Test Plan

A structured plan to create and run automated tests of a function to ensure that it correctly returns valid output.

Signup and view all the flashcards

Input Values (Testing)

Specific values used as input to test a function to cover various possible scenarios.

Signup and view all the flashcards

Expected Output

The anticipated value that the function will return for a given input.

Signup and view all the flashcards

MSTest

A testing framework automating the testing process in .NET.

Signup and view all the flashcards

Data Driven Tests

Tests that use a data set that contains multiple inputs and expected outputs.

Signup and view all the flashcards

Piecewise Linear Function

A function characterized by multiple linear sections used to calculate different rules based on values or limits.

Signup and view all the flashcards

Exceptions in Programming

Exceptions are errors or unusual events during program execution. They are part of normal error handling.

Signup and view all the flashcards

Traditional Error Handling

A method of handling errors where the code changes its path to an alternate code path.

Signup and view all the flashcards

Exception Handling

A method of handling errors where the program unwinds the call stack to find appropriate error handling code.

Signup and view all the flashcards

Exception Advantages

Error handling separated from normal code; recovery from errors is possible.

Signup and view all the flashcards

Exception Misuse

Using exceptions for intended program behaviors or for handling errors that should be handled using error codes.

Signup and view all the flashcards

Exception Types in C#

Exception classes inherit from System.Exception or its subclasses.

Signup and view all the flashcards

Throwing Exceptions

Causing exceptions; they can be thrown explicitly by code or happen naturally, (e.g. invalid input).

Signup and view all the flashcards

Study Notes

Testing Principles

  • Testing is a process to evaluate applications ensuring compliance with requirements.
  • Testing involves systematically identifying potential issues and creating tests to verify behaviour.
  • Testing helps discover, eliminate defects, and identify performance problems.
  • Testing provides an objective assessment of the product's fit to requirements.
  • If errors are found after delivery, tests can be created to reproduce issues and validate corrections.
  • Limitations of testing include constraints on predicting error conditions and exhaustive testing of complex programs.

Alternatives to Testing

  • Static analysis: Checks the source code for vulnerabilities and errors (e.g., memory leaks, buffer overruns).
  • Model checking: Validates application behaviour against a pre-defined mathematical model.
  • Code reviews: Reviewing code by other developers to find defects, security issues, or performance problems.
  • Pair programming: Simultaneous coding and review, helping prevent logic errors.

Kinds of Testing (Part 1)

  • Unit testing: Tests individual components (e.g., methods, classes) in isolation to ensure correctness.
  • Different unit test types: Black box (specifies and contracts, not implementation), glass box (examines the implementation's code).
  • Integration testing: Tests combined components to check interactions.
  • System testing: Validates the entire system's functionality and non-functional requirements (e.g., performance, security).

Kinds of Testing (Part 2)

  • Acceptance testing: Determines if the system meets customer requirements.
  • Regression testing: Verifies that changes in the code do not introduce new defects.
  • Performance testing: Assesses the system's response to different workloads and conditions.
  • Security testing: Identifies vulnerabilities such as buffer overruns, SQL injection, or cross-site scripting.

Test Plan (General Idea)

  • Test plans outline the testing process.
  • It details testing objectives, scope, approach, schedule, and testing procedures.
  • Provides a structured "blueprint" for a testing process.
  • Specifies what will be tested, what will not, and the procedures.

Test Plan (Unit Testing)

  • Test plans are usually in table format.
  • Key columns include: unique test identifier (test number); concise test description; tagging for organisation (e.g., boundary, valid); detailed instructions for test setup; expected outcome details; status (Pass/Fail).

MSTest Overview

  • MSTest is a unit testing framework included in Visual Studio.
  • This framework automates unit tests in Visual Studio.
  • The framework offers a namespace (Microsoft.VisualStudio.TestTools.UnitTesting) with classes and attributes used to code and execute tests.

MSTest Attributes

  • TestClass: Specifies a class containing unit tests.
  • TestMethod: Designates a method as a unit test.
  • TestCategory: Categorises a unit test to group and manage tests effectively.
  • TestInitialize: Executes before each test in the class.
  • ExpectedException: Asserts an expected exception is thrown during testing.
  • Timeout: Sets a time limit for a unit test.
  • DataTestMethod: Executes a unit test with different input.
  • DataRow: Supplies input data to the DataTestMethod.

General Structure of a Unit Test

  • Setup phase: Initializes objects and establishes test conditions.
  • Run phase: Executes the code under test.
  • Assert phase: Verifies results against predicted outcomes.

Case Study 1: Income Tax

  • This case study illustrates unit testing methodology for functions.
  • Test plans are developed to cover various scenarios of input to verify the expected outcome produced (including negative input values).
  • Test types are designed, considering boundary conditions and typical usage in test setup.

Case Study 2: Collection Example

  • Demonstrates unit testing for classes and their methods with various input values.
  • The study validates if the implementation of a class's methods meets the expected outcomes and conditions.

Testing the Collection Example

  • This case study focuses on the procedures needed to test a collection.
  • The code shows how to perform testing of methods (e.g., constructor and Add method) on collections.

Testing the Constructor

  • The test plan ensures that the constructor correctly establishes collections following the expected capacity and size conditions.

Testing the Add Method

  • The add method will be tested under various circumstances, ensuring consistency in the addition of items.

Testing the Minimum Method

  • This method checks that the minimum value is calculated correctly in various collection conditions.
  • The test plan would need to account for empty collections, collections with one item, collections with multiple items, collections starting/ending/in the middle with the minimum and collections with multiples of the minimum value.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Week 09 - Testing CAB201 PDF

Description

Explore the fundamental principles of software testing and its alternatives. This quiz covers methods such as static analysis, model checking, and code reviews, highlighting their roles in ensuring application quality. Test your understanding of testing methodologies and practices in software development.

More Like This

Static Analysis in Software Testing
12 questions
Use Quizgecko on...
Browser
Browser