Unit Testing and TDD Flashcards

(16 cards)

1
Q

What is the primary concept behind Test-Driven Development (TDD)?

A

Write tests based on specifications before writing the code, then build code that passes those tests.

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

What are the benefits of TDD?

A

Integrates specs, coding, and testing; encourages planning before coding; ensures ongoing functionality after changes.

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

What type of testing is TDD an example of?

A

Open Box Testing — because the developer knows the internal structure of the code being tested.

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

What is the difference between open and closed box testing?

A

Open box tests with knowledge of the code test how it is supposed to work (developer testing); closed box tests with no internal knowledge test outputs for inputs (user/release testing).

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

How does JUnit help with TDD?

A

It allows writing tests in separate files using annotations and built-in functions, improving organization and readability.

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

What are some common JUnit assertions?

A

assertEquals, assertTrue, assertFalse, assertNull, assertNotNull, assertSame, assertNotSame.

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

What are JUnit’s @BeforeAll and @AfterAll used for?

A

To set up and tear down test resources (e.g. test files) before and after all tests are run.

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

What are good practices in writing tests?

A

Aim for full line, function, condition, path, and entry/exit coverage; include multiple asserts; don’t modify tests for each case.

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

What is the difference between automated and manual testing?

A

Automated testing uses scripts/code and can run continuously; manual testing involves human interaction and is typically run at stages.

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

What does @Disabled do in JUnit?

A

Temporarily disables a test, similar to commenting it out.

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

What is assertThrows used for in JUnit?

A

To test that a specific exception is thrown by the code.

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

What is a sign of a good test in TDD?

A

It fails initially before the feature is implemented, then passes after correct code is written.

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

What unit testing frameworks exist in other languages?

A

PyUnit (Python), CppTest (C++), NUnit (C#), and many others.

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

What does “testing for the right error” mean?

A

A test should pass when the correct error or exception is triggered, indicating robust error handling.

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

Automated vs manual testing

A

Automated - large amounts of scripted or coded tests, automate large volume data testing, run as often as the code is compiled
Manual - testing example user interactions, run at planned times

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

Good tests have…

A

Line coverage, function coverage, condition coverage, path coverage, entry/exit coverage