Unit Testing & JUnit 4 Flashcards

1
Q

What is unit testing?

A

The independent testing of a certain code block to validate that it works as intended under certain circumsrtances.

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

What is unit testing trying to prove?

A

That a code block works under certain conditions. It’s infeasible to test all conditions though.

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

When should code be tested?

A

Before of concurrently to the test code being implemented into the production code base.

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

What are the 3 main benefits of unit testing?

A
  • Reduces amount of bugs implemented into production code.
  • Tests make program functionality easier to understand.
  • Defined tests help keep project goals defined and prevent scope creep.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the acronym for producing a good unit test?

A

Rightness : Results are as expected.
Boundaries : Operates in defined boundaries.
Inverse : Can check the inverse relationship of the method.
Cross-check : Can be cross-checked by some means.
Errors : Can force error conditions.
Performance Characteristics : Performs as expected under defined conditions.

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

What are the properties of good unit tests?

A

Automatic, Thorough, Repeatable, Independent, Professional (well structured).

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

What is JUnit4?

A

A unit testing framework for java.

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

What are the 4 admin actions all tests should take for good testing?

A
  • Set up testing conditions.
  • Call the methods to be tested.
  • Verify the test results are as expected.
  • Clear up after the test.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which concept underpins almost all testing?

A

Assertions.

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

Can a test have multiple / no assertions?

A

Yes and Yes.

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

Why is it unwise to assertEquals a floating point number?

A

Because, due to memory finiteness, it may not be possible to achieve equality. Therefore, it’s best to use some form of proximity test.

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

How does the fail(String msg) test method work?

A

If the fail() is executed, the test has failed and terminates.

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

What are the typical imports needed for unit testing in JUnit4?

A

Before, BeforeClass, Test, After, AfterClass, Assert.

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