0
0
JUnittesting~10 mins

Why integration tests verify component interaction in JUnit - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an integration test method that checks if two components interact correctly.

JUnit
public void testComponentInteraction() {
    ComponentA a = new ComponentA();
    ComponentB b = new ComponentB();
    a.setDependency([1]);
    boolean result = a.performAction();
    assertTrue(result);
}
Drag options to blanks, or click blank then click option'
Anew ComponentA()
Bnull
Cb
Dnew Object()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing null instead of the dependent component.
Creating a new instance of the wrong component.
Passing a generic Object instead of the specific component.
2fill in blank
medium

Complete the code to assert that the interaction between components returns the expected value.

JUnit
assertEquals([1], a.performAction());
Drag options to blanks, or click blank then click option'
Anull
Bfalse
C0
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using false which indicates failure.
Using null which is not a boolean.
Using 0 which is not a boolean.
3fill in blank
hard

Fix the error in the test setup to correctly initialize the components for integration testing.

JUnit
ComponentA a = new ComponentA();
ComponentB b = [1];
a.setDependency(b);
Drag options to blanks, or click blank then click option'
Anew ComponentB()
Bnull
CComponentB()
Dnew Object()
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning null instead of an instance.
Omitting the new keyword.
Assigning a generic Object instead of the correct component.
4fill in blank
hard

Fill both blanks to complete the integration test that verifies interaction and result.

JUnit
ComponentA a = new ComponentA();
ComponentB b = [1];
a.setDependency(b);
assertEquals([2], a.performAction());
Drag options to blanks, or click blank then click option'
Anew ComponentB()
Btrue
Cfalse
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using false as expected result.
Passing null instead of a component instance.
Mixing up the order of blanks.
5fill in blank
hard

Fill all three blanks to complete the integration test that sets up components, performs action, and asserts the result.

JUnit
ComponentA a = new [1]();
ComponentB b = new [2]();
a.setDependency(b);
boolean result = a.[3]();
assertTrue(result);
Drag options to blanks, or click blank then click option'
AComponentA
BComponentB
CperformAction
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong class names for instances.
Using a method name that does not exist.
Forgetting to assert the result.