Software Testing Principles and Alternatives
47 Questions
0 Views

Software Testing Principles and Alternatives

Created by
@AngelicMarimba2914

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</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</p> Signup and view all the answers

    What happens during stack unwinding when an exception is thrown?

    <p>Important cleanup methods may not execute.</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.</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.</p> Signup and view all the answers

    Which approach is recommended when expecting unusual or invalid values?

    <p>Utilize error codes instead.</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.</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.</p> Signup and view all the answers

    How can cleanup methods be assured execution during exception handling?

    <p>By implementing 'finally' or 'using' statements.</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.</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.</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.</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.</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.</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.</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.</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'.</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.</p> Signup and view all the answers

    What is the primary purpose of MSTest?

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

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

    <p>TestMethod</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</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</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</p> Signup and view all the answers

    Which attribute allows you to categorize unit tests in MSTest?

    <p>TestCategory</p> Signup and view all the answers

    What is the role of DataRow in MSTest?

    <p>To provide different inputs for a DataTestMethod</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</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.</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.</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.</p> Signup and view all the answers

    What are exceptions generally regarded as?

    <p>Undesirable events outside the normal behavior of a program.</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.</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.</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.</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.</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.</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.</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</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.</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</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</p> Signup and view all the answers

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

    <p>Deployment</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</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.</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.</p> Signup and view all the answers

    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

    Use Quizgecko on...
    Browser
    Browser