Testing and Debugging Flashcards

1
Q

Name 3 frameworks you have used?

A

JUnit
Angular
React Native

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

What JUnit annotation allows developers to assign one or more tags to a test case, which can be used to filter the test cases that are executed?

A

@Tag

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

What JUnit annotation specifies the maximum amount of time that a test case should be allowed to run before it is considered to have failed

A

@Timeout

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

What annotation allows developers to specify a custom display name for the test case, which can be more descriptive than the method name.

A

@Displayname

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

What JUnit annotation marks a test case that should be executed multiple times with different input parameters.

A

@ParameterizedTest

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

What JUnit annotation allows developers to specify a set of input parameters that should be passed to the test case.?

A

@Parameters

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

What is JUnit, and what is it used for?

A

JUnit is a test framework that supports TDD and BDD

It does this by providing different annotations, assertions, and test runners that we can use to write and execute tests

It lets us define tests as methods with annotations that give it context and information on how it should be run

provide a set of assert methods that developers can use to test specific conditions and generate appropriate error messages if the tests fail

provides test runners that execute the tests and report the results to the developer ie., filter test results, run until the test passes

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

Name 6 the benefits of using JUnit for testing Java applications

A

Simplifies testing - easier for developers

Automates testing - helps catch errors earlier, making it easier and less costly to fix them

Modular testing - small tests, focus on specific parts of the code

Provides quick feedback - success / failure

Improves code quality

Supports test driven development

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

What are the most common JUnit annotations, and what are they used for?

A

@Test
@Before (before each)
@After (after each)
@BeforeClass (before all tests)
@AfterClass (after all tests)

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

What is the @Before annotation used for?

A

@Before - method should be run before EACH test

ie., initialise variables, create object

@Before
public void setUp() {
obj = new MyClass();
}

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

What is the @BeforeClass annotation used for?

A

@BeforeClass - method should be run once before ANY test method in the class is executed

Ie., initialising a database before any test is executed

@BeforeClass
public static void setUpClass() {
conn = DriverManager.getConnection(
“jdbc:mysql://localhost/mydb”, “user”, “pass”);
}

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

What is a JUnit test suite, and how is it created?

A

A test suite is a collection of test cases that are executed together as a group

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

Describe 5 steps for writing a JUnit test?

A
  1. Create a Test class annotated with @Test
  2. Create a test method and annotate it with @Test
  3. Write test code inside the test method to TEST THE BEHAVIOUR of the method or class under test
  4. Use assertions to verify the expected results are produced
  5. Run the test using a framework like JUnit and verify the tests pass
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a mock object and how is it used in JUnit testing?

A

A mock object is a simulated object that mimics the behavior of a real object in a controlled way.

It can be created using frameworks such as Mockito

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

How do you create a mock object using Mockito?

A

Mockito.mock() method and then define the behavior of the mock object using the when() method.

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

How do you use JUnit to test private methods?

A

it is not recommended to test private methods in JUnit, as they are implementation details and not part of the public API

ways to test them use reflection

17
Q

How do you integrate JUnit with other build tools like Gradle?

A
  1. Add JUnit as a dependency to build.gradle file
  2. Configure test task to run JUnit tests
  3. ./gradlew test
18
Q

How do you debug a problem in production?

A
  1. Reproduce the issue
    - If can’t use logging, monitoring
  2. Analyse the data
    - patterns, error messages etc
  3. Narrow down the scope
    - identify the components, modules causing the issue
  4. Check the logs
  5. Debugging tools to inspect the code
  6. Fix the issue
  7. Monitor the system