Testing Flashcards

1
Q

Why do we test?

A

As a beginner, you should write tests to preventregression. In software development, you can think of regression as an event that causes previously working code to stop working after a change to your code or environment. In effect, your program regresses to an earlier development state.

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

What is the syntax for a jest test?

A

test(‘two plus two is four’, () => {
expect(2 + 2).toBe(4);
});

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

What is the syntax for a test suit?

A

const Car = require(“./car”);

describe(“The Car class”, () => {
test(“has four wheels”, () => {
let car = new Car();
expect(car.wheels).toBe(4);
});
});
// To skip a test: test.skip(“has four wheels”, () => {… or xtest.(‘has….

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

How do you group your Jest tests?

A
  • describe(descriptionString, callback)
    • Thedescribemethod groups your tests. Groups are there to help you structure your tests into logical sections. The string argument describes the group of tests. The callback contains the grouped tests.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What method do you use for a single test?

A
  • test(descriptionString, callback)
    • Each invocation oftestdefines a new test. The string argument describes the test. Within each test, we need to make one or more assertions.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What method provides our matcher methods?

A
  • expect()
    • The argument passed toexpectis the value that we want to assert; it’s often called theactual value. Theexpectmethod, in turn, returns an object that includes a variety ofmatchermethods. Matchers compare the actual value passed toexpectwith the expected value, but don’t return a meaningful value. (In particular, they don’t return a boolean value.) Instead, they simply inform Jest of the results, and Jest takes care of treating that result as a success or failure.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a test suite?

A

The entire set of tests that accompanies your program or application. You can think of it as all of the tests for a project.

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

What is a test?

A

ATestis a specific situation or context that you’re attempting to test. For instance, a test may attempt to verify that you get an error message when you try to log in with the wrong password. Each test can contain multiple assertions. You may sometimes see tests referred to asspecs.

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

What is an assertion?

A

AnAssertionis the verification step that confirms that your program did what it should. In particular, many assertions test whether the return value of a function or method matches the expected results. You can make multiple assertions within a test. Assertions are also calledexpectations.

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

How do we invert a matcher?

A

Using .not :

test(‘car has wheels’, () => {
let car = new Car();
expect(car.wheels).not.toBeUndefined();
});

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

What is the SEAT approach?

A
  • Set up the necessary objects.
  • Execute the code against the object we’re testing.
  • Assert the results of execution.
  • Tear down and clean up any lingering artifacts.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What method do we use to reset the variables before each test?

A

let car;
beforeEach(() => {
car = new Car();
});

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

What callback is called after each test? (if provided)

A

afterEach()

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

What is code coverage?

A

code coverage is the percentage of functions or methods called by your tests or the percentage of lines of code that executed as a result of your tests.

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

How do you find code coverage in jest?

A

jest –coverage fileName.test.js

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

Which Jest coverage metric is the most useful?

A

The “% Lines” column shows the most useful data: this is the percentage of program lines that got executed at least once during testing.

17
Q

What are our most commonly used jest matchers? What are the differences between them?

A

thetoBeandtoEqualmatchers. toBe tests ===, toEqual is the same as toBe but can also test object equality.