Unit 4: Various Testing Frameworks Available in Java - Practice Quiz
1 Which factor is important when selecting an automated testing tool?
2 Which criterion helps determine whether a testing tool is practical for a team?
3 What is Jenkins mainly used for?
4 What can Jenkins automatically do after code is committed?
5 What is TestNG?
6 Which annotation commonly identifies a test method in TestNG?
7 What is Maven primarily used for in a Java project?
8 Which file commonly contains Maven project configuration?
9 Which annotation is used in JUnit 5 to mark a test method?
10 Which component is the programming model used by JUnit 5?
11 What is Gherkin mainly used to write?
12 Which Gherkin keyword usually describes an initial condition?
13 What is JUnit?
14 What is the main purpose of a unit test?
15 Which annotation defines a test method in a JUnit test class?
16 Which is a commonly recommended name for a JUnit test method?
17 What is the purpose of a JUnit test suite?
18 Which assertion checks that two values are equal in JUnit?
19 Which JUnit construct is used to check an expected result?
20 Which Eclipse feature can run a JUnit test class?
21 A development team needs a Java testing tool that supports parameterized tests, parallel execution, and flexible grouping of tests. Which tool best satisfies these requirements?
22 A team is selecting an automated testing tool for a long-term project. Which factor is most important for reducing integration effort?
23 A Jenkins pipeline must compile a Maven project and then execute its unit tests. Which sequence of stages is most appropriate?
24 A Jenkins job should run automatically whenever code is pushed to a Git repository. Which mechanism is most suitable?
25 A TestNG test method should run with three different username and password combinations. Which TestNG feature should be used?
@AfterSuite
@IgnoreAll
@FactoryTest
@DataProvider
26
In TestNG, generateReport() must run only after executeTests() completes successfully. Which configuration expresses this requirement?
priority = "executeTests"
groups = "executeTests"
dataProvider = "executeTests"
dependsOnMethods = "executeTests"
27
A Maven project stores its JUnit tests under src/test/java. Which command compiles the project and runs those tests without packaging the application?
mvn clean
mvn test
mvn site
mvn deploy
28 JUnit should be available when compiling and running tests but should not be included as a runtime dependency of the application. Which Maven dependency scope is appropriate?
runtime
test
compile
provided
29
A JUnit 5 test must execute the same method for the values 2, 4, and 6. Which annotation combination is appropriate?
@Test with @Order
@RepeatedTest with @Tag
@ParameterizedTest with @ValueSource
@TestFactory with @DisplayName
30
A JUnit 5 test should verify that calling withdraw(200) on an account with insufficient funds throws InsufficientFundsException. Which assertion should be used?
assertTrue(withdraw(200) instanceof InsufficientFundsException)
assertEquals(InsufficientFundsException.class, withdraw(200))
assertThrows(InsufficientFundsException.class, () -> withdraw(200))
assertDoesNotThrow(() -> withdraw(200))
31 Which Gherkin scenario correctly describes a successful login using behavior-focused steps?
Given Java is installed, When Maven compiles, Then Jenkins restarts
Given click username, When type password, Then call the login method
Given the database table, When SQL runs, Then close the browser driver
Given the login page is open, When valid credentials are submitted, Then the dashboard is displayed
32 Several Gherkin scenarios require the user to be authenticated before their individual steps begin. Where should the shared authentication step be placed?
Background section
Feature title
Examples heading
Then comment
33 A developer changes the implementation of a calculator while keeping its public behavior unchanged. How does a JUnit regression suite help?
34 Which JUnit 5 method is correctly defined as a test?
@Test int addsNumbers() { return 2 + 3; }
@Test void addsNumbers(int value) { assertEquals(5, value); }
void @Test addsNumbers() { assertEquals(5, 2 + 3); }
@Test void addsNumbers() { assertEquals(5, 2 + 3); }
35 Which test method name most clearly communicates the condition and expected result?
withdraw_whenBalanceIsInsufficient_throwsException()
calculate()
runAccountCode()
testMethod1()
36
A JUnit 5 suite should include every test class in the package com.example.payment. Which suite configuration is appropriate?
@Test with @SelectMethods("com.example.payment")
@Suite with @SelectPackages("com.example.payment")
@TestFactory with @ImportPackage("com.example.payment")
@BeforeAll with @IncludePackages("com.example.payment")
37
A method isEven(8) returns true. Which JUnit assertion most directly verifies this behavior?
assertThrows(Boolean.class, () -> isEven(8))
assertTrue(isEven(8))
assertNull(isEven(8))
assertSame(8, isEven(8))
38
A fresh DatabaseConnection must be created before every JUnit 5 test to prevent tests from sharing state. Which annotation should be applied to the setup method?
@BeforeEach
@Disabled
@AfterAll
@BeforeAll
39 A JUnit test run in Eclipse displays a red progress bar, although most tests passed. What does the red bar indicate?
40
A Maven-based Java project needs JUnit 5 tests to run during mvn test. Which setup is required?
test scope
41 A Java team must select a testing tool for a modular application. The build runs offline in a restricted network, tests require parallel execution, and reports must integrate with an existing CI server. Which evaluation approach best reduces adoption risk?
42 Two candidate tools satisfy all functional requirements. Tool X has lower license cost but requires proprietary test scripts, while Tool Y uses standard Java APIs and integrates with the current Maven lifecycle. Which factor most strongly favors Tool Y over the application's expected ten-year lifetime?
43
A Jenkins Pipeline uses the following stage:
stage('Test') { steps { sh 'mvn test' } post { always { junit 'target/surefire-reports/*.xml' } } }
Several tests fail. Assuming Maven Surefire returns a nonzero exit code, what is the most likely behavior?
junit step converts failures into warnings
post block is skipped because the sh step terminated unsuccessfully
44
A Jenkins controller has Linux and Windows agents. UI tests require Chrome installed only on agents labeled ui-linux, while compilation may run anywhere. Which Declarative Pipeline design most accurately enforces this constraint?
agent any globally and set CHROME_HOME in the UI stage
agent { label 'ui-linux' } globally for every pipeline stage
agent none globally and assign agents to individual stages
45
A TestNG data provider is declared as @DataProvider(name = "users", parallel = true). Multiple invocations update the same mutable instance field in the test class. Which change most directly makes the tests reliable under parallel execution?
priority values to all methods using the data provider
parallelUsers
46
In TestNG, createAccount() is annotated with @Test, and deleteAccount() is annotated with @Test(dependsOnMethods = "createAccount"). If createAccount() fails, what is the default outcome for deleteAccount()?
47
A Maven project has unit tests named PriceTest and integration tests named PaymentIT. The build must run unit tests during test and integration tests during integration-test, with integration-test failures checked during verify. Which plugin allocation is conventional?
PriceTest and Surefire for PaymentIT
PriceTest and Surefire for PaymentIT
PriceTest and Failsafe for PaymentIT
48
A multi-module Maven build contains modules domain, service, and web, where web depends on service, and service depends on domain. From the reactor root, what does mvn -pl service -am test request?
service while resolving all dependencies remotely
service and also build its required reactor dependencies
service and also build every module that depends on it
service
49
A JUnit Jupiter parameterized test receives strings through @ValueSource(strings = {"42", "-1"}), but the method parameter type is int. Why can this test execute without a custom converter?
int
50
A JUnit Jupiter test class uses the default per-method lifecycle. Its non-static @BeforeAll method fails discovery with a validation error. Which change permits the method to remain non-static?
@Nested
@TestInstance(PER_CLASS)
@BeforeEach and @BeforeAll
51
A Gherkin scenario outline contains placeholders <role> and <status>, with three rows in its Examples table. How should a runner normally interpret the outline?
52 Which Gherkin design best preserves business readability while avoiding unnecessary coupling to a web interface?
When Selenium clicks the button with id refund-submit
When the test calls POST /v2/refunds with status code 201 expected
When the customer submits a valid refund request
When the automation framework waits exactly 500 milliseconds, locates the third form element, and dispatches a browser click event
53 A project contains JUnit 4 tests and newly written JUnit Jupiter tests. Maven discovers the Jupiter tests but ignores the JUnit 4 tests. Which additional JUnit Platform component is specifically intended to execute the older tests?
54
Consider this JUnit Jupiter method:
@Test void transfer() { assertThrows(InsufficientFundsException.class, () -> account.transfer(100)); }
The transfer throws a subclass of InsufficientFundsException. What is the result?
assertThrows accepts subclasses
55 A Maven project uses the default Surefire test-name patterns. Which JUnit test class is least likely to be discovered solely because of its filename?
PaymentSpecification.java
PaymentTest.java
PaymentTestCase.java
TestPayment.java
56
A JUnit Platform suite is annotated with @Suite, @SelectPackages("com.example"), and @IncludeTags("fast"). What is the intended selection behavior?
com.example and retain those tagged fast
fast, then include classes carrying a com.example annotation
com.example tests before tagged tests
com.example and add the tag fast to them
57
A JUnit Jupiter test uses assertAll("account", () -> assertEquals(10, account.balance()), () -> assertFalse(account.isLocked())). Both assertions fail. What behavior should be expected?
assertAll is intended only for diagnostic checks
58
A JUnit Jupiter test calls assertTimeout(Duration.ofMillis(100), () -> service.compute()), and compute() takes 150 ms before returning normally. Which statement is correct?
59 A JUnit Jupiter test runs from Maven, but Eclipse reports that no tests were found when using an outdated Eclipse installation. The project classpath is otherwise correct. What is the most appropriate diagnosis?
junit.framework.TestCase before its runner can discover annotations
60 A Maven project should compile and run JUnit Jupiter tests without packaging JUnit APIs into the production artifact. Which dependency setup is most appropriate when dependency versions are managed separately?
org.junit.vintage:junit-vintage-engine with scope provided, because Vintage contains the complete Jupiter programming and execution APIs
junit:junit with scope runtime
org.junit.jupiter:junit-jupiter with scope test
org.junit.platform:junit-platform-launcher with scope compile
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →