Testing Fundamentals

UserFriendlyOrphism avatar
UserFriendlyOrphism
·
·
Download

Start Quiz

Study Flashcards

16 Questions

What is the primary purpose of testing?

To evaluate a system or component to satisfy specified requirements

What is the benefit of Automated Testing?

Early detection of bugs

What is the purpose of Unit Testing?

To test individual units or components of a software application

What is JUnit5?

An API to write tests for Java applications

What is the purpose of Test Discovery?

To discover and run tests

What is Code Coverage?

A measure of how many lines of code are executed during automated tests

What is the purpose of @BeforeEach annotation?

To execute code before each test method

What is the purpose of Mocking Tests?

To isolate dependencies in unit tests

What is the purpose of JaCoCo?

To declare minimum requirements that should be met, otherwise the build will fail

What is mocking in the context of testing?

A technique used in testing to create objects that simulate the behavior of real objects

What is a stub in the context of mocking?

An object that provides predefined responses to method calls

What is the main goal of CI/CD?

To enhance the efficiency, quality, and speed of software development

What is the main benefit of CI/CD?

Faster Delivery

What is the first step in the TDD process?

Write a failing test that describes a piece of desired functionality

What is a spy in the context of mocking?

An object that records the interactions with the real objects it is spying on

What is the command to generate a JaCoCo report?

mvn clean test jacoco:report

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.

This quiz covers the basics of testing, including levels of testing, unit testing, JUnit5, test discovery, and more. It also introduces test-driven development and continuous integration with GitHub Actions.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

JUnit
5 questions

JUnit

InvulnerableClarity avatar
InvulnerableClarity
Mastering Unit Testing in Java
10 questions
Unit Testing Fundamentals
30 questions
Use Quizgecko on...
Browser
Browser