Chapter 8 - Testing Flashcards

1
Q

test pyramid

A

pyramid partitions the tests according to their granularity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Unit tests

A

check small parts of the code, usually a single class.

They form the base of the pyramid, meaning most tests fall into this category. Unit tests are simple, easier to implement, and fast to run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

integration tests or service tests

A

verify a system’s functionality or transaction

These tests involve multiple classes from different packages and may include external components like databases. They require more time to implement and are slower to run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

end-to-end tests, also referred to as user interface tests or system tests

A

simulate a user session on the system as authentically as possible.

They are more complex, time-consuming, and fewer in number. End-to-end tests also tend to be brittle, meaning minor alterations in the user interface might require changes in these tests.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Automated test percentage breakdown

A

A generic recommendation suggests that automated tests should be implemented in the following proportion: 70% as unit tests; 20% as integration tests; and 10% as end-to-end tests

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

defect (bug)

A

when a piece of code does not comply with its specification

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

failure

A

If defective code is executed and causes the program to produce an incorrect result or behavior

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

fixture

A

create the test context

This involves instantiating the objects we intend to test and, if necessary, initializing them

The program state verified by one or more test methods, including data, objects, etc. In the context of unit testing, the function of a fixture is to fix the state, i.e., set up the data and objects to be verified by the test.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Test Method

A

A method that implements a test and is annotated with the @Test annotation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Test Case

A

In JUnit, the term refers to a class containing test methods. The name originates from the first versions of JUnit, where the test methods were implemented in classes that inherited from a TestCase class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Test Suite

A

A set of test cases typically executed together by the unit testing framework, which in our case is JUnit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

System Under Test (SUT)

A

The system being tested. It’s a generic term, also used in other types of tests, not limited to unit tests. The term production code is also sometimes used to refer to the SUT.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Test-Driven Development

A

Development style: you can write the tests first, before any production code. Initially, these tests will fail. Thus, you start with code that only compiles but whose tests fail. Then you implement the production code and test again. At this point, the tests should pass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

regressions

A

occurs when a modification in one part of the code—whether to fix a bug, implement a new feature, or perform a refactoring—inadvertently introduces a bug in another part.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

FIRST

A

Fast
Independent
Repeatable
Self-checking
Timely

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Fast

A

Developers must run unit tests frequently to receive feedback about bugs and regressions. Therefore, it’s important that these tests execute quickly, ideally in milliseconds.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Independent

A

The order of execution of unit tests should not matter. For any two tests T1 and T2, running T1 followed by T2 must produce the same result as running T2 and then T1. Indeed, T1 and T2 could also be executed concurrently. For the tests to be independent, T1 should not change any part of the global state that is later used by T2, and vice versa.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Repeatable

A

Unit tests should always provide the same result. This means that if a test T is called n times, the result should be the same in all n executions. Therefore, T should either pass in every execution or fail in every execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Self-checking

A

The result of unit tests should be easily verifiable. Developers should not have to open and analyze an output file or manually provide input data to interpret the test result. Instead, the results should be displayed in the IDE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Timely

A

Tests should be written as early as possible, ideally even before the code that needs to be tested.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Flaky Tests or Erratic Tests

A

Tests with non-deterministic results

Concurrency is one of the main causes of flaky behavior

22
Q

Test Smells

A

represent sub-optimal implementation decisions in test code, which, in principle, should be avoided

Includes:
Obscure Test
Tests with Conditional Logic
Code Duplication

23
Q

Obscure Test

A

a long, complex, and difficult-to-understand test

24
Q

Tests with Conditional Logic

A

include code that may not be executed.

25
Q

Code Duplication

A

occurs when there are repeated blocks of code in several test methods

26
Q

Test coverage

A

a metric that helps determine the number of tests we need to write for a program.

It measures the percentage of statements in a program executed by the existing tests, calculated as:

Test coverage = (Number of statements executed by the tests) / (Total number of statements in the program)

27
Q

function coverage

A

percentage of functions executed by the tests

28
Q

function call coverage

A

among all the statements in a program that call functions, the percentage exercised by the tests

29
Q

branch coverage

A

percentage of branches in a program executed by the tests; an if always generates two branches: one when the condition is true and another when it is false

C1 Coverage

30
Q

C0 Coverage vs C1 Coverage

A

C0 Coverage: Statement coverages
C1 Coverage: branch coverages

31
Q

Testability

A

describes how easy it is to test a program

32
Q

mock (or stub)

A

we can create an object that emulates the real object, but only for testing purposes.

33
Q

behavioral test

A

checks for events (e.g., method calls) that occur during the execution of the tests

34
Q

Dummy Objects

A

passed as arguments to a method but they are not used in the method’s body. Their primary purpose is to bypass the language’s type system

35
Q

Fake Objects

A

have a simpler implementation than a real object. For example, they can simulate a database in main memory.

36
Q

test doubles

A

mocks and stubs
Dummy Objects
Fake Objects

37
Q

service tests (or integration tests)

A

These tests aim to exercise a complete service, or a complete feature of the system, rather than testing a small unit of code

involve more classes, sometimes from distinct packages. They also test dependencies and real systems, such as databases and remote services.

38
Q

system tests or interface tests (end-to-end tests)

A

These tests simulate the use of a system by a real user. They are the most resource-intensive automated tests, requiring more effort to implement and taking the longest to execute.

39
Q

black-box technique

A

tests are written considering only the interface of the code under test.

functional tests

40
Q

white-box technique

A

test implementation takes into account information about the code and its structure

structural tests

41
Q

Equivalence Classes

A

recommends dividing the inputs of a program into sets of values that have the same likelihood of presenting a bug

42
Q

Boundary Value Analysis

A

testing with the boundary values of each equivalence class and with the values that immediately precede or succeed such boundaries.

43
Q

exhaustive testing

A

testing a program with all possible inputs

44
Q

Random testing

A

the test data is chosen randomly

45
Q

Acceptance Tests

A

tests carried out by the customers, using their own data. The results determine whether or not the customers will accept the implemented software.

46
Q

Alpha tests

A

conducted with customers, but in a controlled environment, such as the developer’s workstation

47
Q

beta tests

A

If the system passes the alpha tests, a test with a larger customer group can be conducted, no longer in a controlled environment

48
Q

performance tests

A

to assess the system’s behavior under specific load conditions

49
Q

Usability tests

A

used to evaluate the system’s user interface and often involve the observation of real users interacting with the system

50
Q

Failure tests

A

simulate abnormal events in a system, such as the failure of specific services or even an entire data center.