0
0
JUnittesting~10 mins

Builder pattern for test data in JUnit - Interactive Code Practice

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

Complete the code to start building a User object using the builder pattern.

JUnit
User user = User.[1]();
Drag options to blanks, or click blank then click option'
Abuilder
Bnew
Ccreate
Dbuild
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new' instead of 'builder()' to start the builder.
Using 'build()' which is used to finish building, not start.
2fill in blank
medium

Complete the code to set the user's name in the builder.

JUnit
User user = User.builder().[1]("Alice").build();
Drag options to blanks, or click blank then click option'
AuserName
BsetName
CwithName
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'setName' which is common in setters but not in builders.
Using 'withName' which is sometimes used but not here.
3fill in blank
hard

Fix the error in the builder usage to correctly set the user's age.

JUnit
User user = User.builder().age[1]30).build();
Drag options to blanks, or click blank then click option'
A=
B(
C.
D->
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which is an assignment, not a method call.
Using '.' without parentheses which causes syntax error.
4fill in blank
hard

Fill both blanks to build a User with email and then finish building.

JUnit
User user = User.builder().[1]("user@example.com").[2]();
Drag options to blanks, or click blank then click option'
Aemail
Bbuild
CsetEmail
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'setEmail' which is not typical in builder patterns.
Using 'create' which is not the method to finish building.
5fill in blank
hard

Fill all three blanks to build a User with name, age, and then finish building.

JUnit
User user = User.builder().[1]("Bob").[2](25).[3]();
Drag options to blanks, or click blank then click option'
Aname
Bage
Cbuild
DsetAge
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'setAge' instead of 'age' for the builder method.
Forgetting to call 'build()' at the end.