Software Testing: Unit Testing and Frameworks
13 Questions
1 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 primary goal of unit testing?

  • To prepare the code for deployment
  • To test the code in small, individual units (correct)
  • To analyze the performance of the software application
  • To validate user requirements
  • Which of the following steps is NOT part of the unit testing process?

  • Gathering return values to compare with expected output
  • Deploying the code to production (correct)
  • Feeding the function specific values
  • Using assertions to handle test failures
  • What does test coverage measure?

  • The depth of testing in terms of feature completeness
  • The performance impact of the tests on the system
  • The extent to which the source code is tested by test cases (correct)
  • The number of test cases executed during testing
  • Which command is used to compile code with counting flags for test coverage?

    <p>gcc -Wall -fprofile-arcs -ftest-coverage -o insert insert.c</p> Signup and view all the answers

    What is the role of assertions in unit testing?

    <p>To throw exceptions if the test fails</p> Signup and view all the answers

    What is the purpose of the Assert::AreEqual method?

    <p>To compare two values and throw an exception if they are not equal</p> Signup and view all the answers

    Which of the following test methods correctly validates a square operation?

    <p>Assert::AreEqual(64.0, d);</p> Signup and view all the answers

    What would be the outcome of calling the IsTrue method with a false boolean?

    <p>It throws an exception</p> Signup and view all the answers

    What is the expected result of the CubeTest method when evaluating cube(3.0)?

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

    Which of the following correctly describes the Fail method?

    <p>It causes the test to fail immediately and displays an optional message</p> Signup and view all the answers

    Which of the following statements about the MathIntegrationTest class is true?

    <p>It is part of the MathTestSuite namespace.</p> Signup and view all the answers

    In which scenario would the AreNotEqual method be used?

    <p>When two values should not match each other</p> Signup and view all the answers

    What would the output be if Assert::AreEqual(91.0, d + d1) is called with d = square(8.0) and d1 = cube(3.0)?

    <p>An exception is thrown due to unequal values</p> Signup and view all the answers

    Study Notes

    Software Testing - Unit Testing

    • Unit testing is the process of testing small units of code.
    • Typically, these units correspond to functions.
    • Steps to test units:
      • Provide specific input values to the function.
      • Collect the return value from the function.
      • Compare the return value to the expected output.
      • If the actual output matches the expected output, the test passes.

    Software Testing - Test Frameworks

    • Unit test frameworks aid in setting up tests.
    • Frameworks allow for calling functions and storing results.
    • The result is compared to the expected outcome.
    • Assertions are used to throw exceptions if tests fail.
    • The framework also involves a teardown step.
    • Common steps within unit test frameworks include
      • Test Setup
      • Execution (calling the function under test)
      • Checking the result (comparing to expected outcome)
      • Test Tear-Down (cleanup)

    Software Testing - Test Coverage

    • Test coverage assesses how much of the source code is covered by a set of test cases.
    • It's a metric for evaluating testing efficiency.
    • Measures the lines of code executed during tests.
    • Measures how many times each line of code is executed.
    • Steps to perform test coverage analysis:
      • Compile the code with special flags for coverage.
      • Execute the target program.
      • Generate a report using the gcov tool.
      • Examine the generated *.gcov file to see line-by-line coverage and execution count data.

    Software Testing - Test Math Functions

    • Example includes for testing math functions in C code(using Header file):
      • mathfuncs.h (header file): Contains function declarations (square and cube).
      • mathfuncs.c: Contains function definitions for square and cube.
      • main: Example usage of the square method.

    Creating a Test Project

    • Several templates are available for different programming languages (C++, etc.).
    • Available templates include Native Unit Test Project, Console App, and Library projects.

    Writing Test Code

    • Includes header files for unit testing (such as CppUnitTest.h).
    • Uses a test framework (e.g., Microsoft Visual Studio's CppUnitTestFramework).
    • Examples of test methods:
      • SquareTest: Tests the square function.
      • CubeTest: Tests the cube function.
      • AdditionTest: Tests addition of function outputs (e.g., square(8) + cube(3)).

    Access C Include File

    • The C include file (mathfuncs.h) is included into the test framework.

    Assertions

    • Methods for checking conditions within the tests:
      • AreEqual(v1, v2) compares values and throws exceptions if they are not equal.
      • AreNotEqual(v1, v2) compares for inequality, throwing exceptions on equality.
      • IsTrue(b1) checks for b1 being true.
      • IsFalse(b1) checks for b1 being false.
      • Fail() forces a test failure.

    Setup Library Path

    • This involves setting up the correct paths within Visual Studio for linking required libraries.
    • The process involves configuring the library paths to allow linking with needed libraries.

    Setup Include Path

    • Setting the directory where header files reside
    • This ensures the compiler can find the required project headers.

    Running Tests in Visual Studio

    • Test Explorer window allows controlling and running tests.
    • Results are displayed in the explorer window, indicating durations, success or failure, etc.

    Test Results

    • Test explorer displays results such as duration, success, failure conditions.
    • Reports can be filtered using the menu.

    Setup and Teardown Before/After Tests

    • TEST_MODULE_INITIALIZE sets up resources for the module.
    • TEST_MODULE_CLEANUP releases resources of the module.
    • TEST_CLASS_INITIALIZE and TEST_CLASS_CLEANUP are similar but for individual test classes.

    Test from Command Line

    • Executable tool vstest from the command line is used to run tests.
    • The tool reports test pass/fail conditions and durations.

    Studying That Suits You

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

    Quiz Team

    Related Documents

    Software Testing Unit Tests PDF

    Description

    This quiz focuses on the fundamentals of unit testing, including its processes, frameworks, and coverage assessments. You will learn about the steps involved in conducting unit tests, utilizing test frameworks effectively, and understanding test coverage principles. Whether you're new to software testing or looking to refresh your knowledge, this quiz is for you.

    More Like This

    The Most Dangerous Game" Unit Test
    6 questions
    CSC 1060 Project Test Framework
    5 questions

    CSC 1060 Project Test Framework

    CharismaticSerpentine5245 avatar
    CharismaticSerpentine5245
    Use Quizgecko on...
    Browser
    Browser