Testing Fundamentals

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 purpose of testing?

  • To evaluate a system or component to satisfy specified requirements (correct)
  • To refactor code
  • To identify bugs in the software
  • To write documentation for the software

What is the benefit of Automated Testing?

  • Collaboration among developers
  • Code refactoring
  • Early detection of bugs (correct)
  • Detection of bugs late in the development cycle

What is the purpose of Unit Testing?

  • To test the user interface
  • To test individual units or components of a software application (correct)
  • To test the database
  • To test the entire application

What is JUnit5?

<p>An API to write tests for Java applications (A)</p> Signup and view all the answers

What is the purpose of Test Discovery?

<p>To discover and run tests (D)</p> Signup and view all the answers

What is Code Coverage?

<p>A measure of how many lines of code are executed during automated tests (A)</p> Signup and view all the answers

What is the purpose of @BeforeEach annotation?

<p>To execute code before each test method (A)</p> Signup and view all the answers

What is the purpose of Mocking Tests?

<p>To isolate dependencies in unit tests (D)</p> Signup and view all the answers

What is the purpose of JaCoCo?

<p>To declare minimum requirements that should be met, otherwise the build will fail (A)</p> Signup and view all the answers

What is mocking in the context of testing?

<p>A technique used in testing to create objects that simulate the behavior of real objects (C)</p> Signup and view all the answers

What is a stub in the context of mocking?

<p>An object that provides predefined responses to method calls (B)</p> Signup and view all the answers

What is the main goal of CI/CD?

<p>To enhance the efficiency, quality, and speed of software development (B)</p> Signup and view all the answers

What is the main benefit of CI/CD?

<p>Faster Delivery (C)</p> Signup and view all the answers

What is the first step in the TDD process?

<p>Write a failing test that describes a piece of desired functionality (C)</p> Signup and view all the answers

What is a spy in the context of mocking?

<p>An object that records the interactions with the real objects it is spying on (C)</p> Signup and view all the answers

What is the command to generate a JaCoCo report?

<p>mvn clean test jacoco:report (C)</p> Signup and view all the answers

Flashcards are hidden until you start studying

Study Notes

Testing

  • Testing is the process of evaluating a system or its component(s) to find whether it satisfies the specified requirements or not.
  • It involves the execution of a system or application to identify any gaps, errors, or missing requirements in the software.

Levels of Testing

  • No specific information provided

Unit Testing

  • Unit Testing is a software testing technique where individual units or components of a software application are tested in isolation from the rest of the application.
  • It provides benefits such as automated testing, early detection of bugs, documentation, code refactoring, collaboration, and regression testing.

JUnit5

  • JUnit5 is an API to write tests, mainly for use by developers.
  • It provides a mechanism for discovering and running tests, and an API to allow easy interaction with IDEs and tools.
  • JUnit5 consists of JUnit Platform, JUnit Jupiter, and JUnit Vintage.
  • It offers benefits such as annotations and extensions, parameterized tests, backward compatibility, improved assertions API, and improved IDE support.

Test Discovery

  • Test classes should follow the JUnit 5 naming conventions, ending with "Tests" or "TestCase".
  • Test methods should be annotated with @Test or @ParameterizedTest.
  • Test classes and methods are not required to be public, but they must not be private.

JUnit Annotations

  • @BeforeEach: before each test
  • @AfterEach: after each test
  • @BeforeAll: before all tests
  • @AfterAll: after all tests
  • @Test: denotes a test method
  • @Tag: used to filter tests
  • @DisplayName: sets a custom display name for a test
  • @Disabled: disables a test
  • @Enabled: enables a test
  • @TestFactory: defines a test factory
  • @ParameterizedTest: runs a test with different parameters
  • @RepeatedTest: runs a test repeatedly

Code Coverage using Jacoco

  • Code coverage is a software metric used to measure how many lines of our code are executed during automated tests.
  • Add the jacoco plugin in your pom.xml file to use JaCoCo.
  • JaCoCo offers a simple way of declaring minimum requirements that should be met, otherwise the build will fail.
  • Run $ mvn clean test jacoco:report to see the coverage report.

Mocking using Mockito

  • Mocking is a technique used in testing to create objects that simulate the behavior of real objects.
  • It helps isolate the code being tested by replacing real dependencies with objects that can be controlled.
  • Stubs: objects that provide predefined responses to method calls.
  • Spies: objects that record the interactions with the real objects they are spying on.
  • Double: a general term for any object used as a substitute for a real object during testing.

Test Driven Development

  • Test-Driven Development (TDD) is a software development approach where tests are written before the actual code.
  • The development process in TDD follows these basic steps:
    • Write a failing test that describes a piece of desired functionality.
    • Write the minimum amount of code needed to make the test pass.
    • Refactor the code to make it clean, improving its design without changing its behavior.
    • Repeat the process.

CI/CD (Continuous Integration/Continuous Deployment)

  • CI/CD is a set of best practices and a software development approach that aims to enhance the efficiency, quality, and speed of software development.
  • It involves the automated integration of code changes, testing, and the continuous deployment of applications.
  • Benefits of CI/CD include:
    • Faster Delivery
    • Higher Quality
    • Consistency
    • Collaboration
    • Feedback Loop
  • Tools for CI/CD include GitHub Actions, Jenkins, TeamCity, CircleCI, and GitLab CI/CD.

Studying That Suits You

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

Quiz Team

More Like This

JUnit
5 questions

JUnit

InvulnerableClarity avatar
InvulnerableClarity
Use Quizgecko on...
Browser
Browser