Unit 4: Various Testing Frameworks Available in Java - Practice Quiz

CSE376 — Automated Testing 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which factor is important when selecting an automated testing tool?

Testing Tools Selection Criteria Easy
A. Number of website pages
B. Compatibility with the project
C. Computer brand only
D. Color of the tool logo

2 Which criterion helps determine whether a testing tool is practical for a team?

Testing Tools Selection Criteria Easy
A. Screen brightness
B. Office location
C. Keyboard layout
D. Learning curve

3 What is Jenkins mainly used for?

Fundamentals of Jenkins Easy
A. Video playback
B. Continuous integration
C. Image editing
D. Database design

4 What can Jenkins automatically do after code is committed?

Fundamentals of Jenkins Easy
A. Design a new programming language
B. Build and test the code
C. Change the project's business requirements
D. Replace the development team

5 What is TestNG?

TestNG Easy
A. A web browser
B. A source-code editor
C. A Java database
D. A Java testing framework

6 Which annotation commonly identifies a test method in TestNG?

TestNG Easy
A. @Test
B. @Check
C. @Run
D. @Verify

7 What is Maven primarily used for in a Java project?

Maven Easy
A. Creating operating systems
B. Project building and dependency management
C. Managing computer hardware
D. Drawing application interfaces

8 Which file commonly contains Maven project configuration?

Maven Easy
A. project.ini
B. pom.xml
C. test.java
D. build.txt

9 Which annotation is used in JUnit 5 to mark a test method?

JUnit 5 Easy
A. @JUnitTest
B. @RunTest
C. @Test
D. @TestCase

10 Which component is the programming model used by JUnit 5?

JUnit 5 Easy
A. JUnit Jupiter
B. JUnit Runner
C. JUnit Builder
D. JUnit Classic

11 What is Gherkin mainly used to write?

Gherkin Easy
A. Java bytecode
B. Network protocols
C. Database indexes
D. Behavior descriptions

12 Which Gherkin keyword usually describes an initial condition?

Gherkin Easy
A. When
B. Given
C. Scenario
D. Then

13 What is JUnit?

Introduction to JUnit Framework Easy
A. A graphic-design framework
B. A version-control system
C. A unit-testing framework for Java
D. A Java application server

14 What is the main purpose of a unit test?

Introduction to JUnit Framework Easy
A. To deploy an application
B. To test a small unit of code
C. To create project documentation
D. To configure a computer network

15 Which annotation defines a test method in a JUnit test class?

Define a Test in JUnit Easy
A. @Unit
B. @Method
C. @Test
D. @Execute

16 Which is a commonly recommended name for a JUnit test method?

JUnit Naming Conventions Easy
A. shouldAddTwoNumbers
B. method1
C. test
D. AddTwoNumbers

17 What is the purpose of a JUnit test suite?

JUnit Test Suites Easy
A. To replace all test methods
B. To compile the Java compiler
C. To store application passwords
D. To group tests for execution

18 Which assertion checks that two values are equal in JUnit?

Example JUnit Test Easy
A. checkEqualsValue
B. assertSameText
C. verifyMatchingData
D. assertEquals

19 Which JUnit construct is used to check an expected result?

JUnit Code Constructs Easy
A. Import
B. Constructor
C. Assertion
D. Package

20 Which Eclipse feature can run a JUnit test class?

Eclipse Support for JUnit Easy
A. Format As Web Page
B. Export As Image
C. Run As JUnit Test
D. Open As Database

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?

Testing Tools Selection Criteria Medium
A. Jenkins
B. TestNG
C. Gherkin
D. JUnit 3

22 A team is selecting an automated testing tool for a long-term project. Which factor is most important for reducing integration effort?

Testing Tools Selection Criteria Medium
A. Location of the vendor's main office
B. Length of the tool's product name
C. Compatibility with the existing technology stack
D. Number of colors in the test report

23 A Jenkins pipeline must compile a Maven project and then execute its unit tests. Which sequence of stages is most appropriate?

Fundamentals of Jenkins Medium
A. Test followed by source checkout
B. Deploy followed by source checkout
C. Report followed by dependency removal
D. Checkout followed by build and test

24 A Jenkins job should run automatically whenever code is pushed to a Git repository. Which mechanism is most suitable?

Fundamentals of Jenkins Medium
A. A repository webhook
B. A manual workspace lock
C. A JUnit assertion
D. A Maven dependency scope

25 A TestNG test method should run with three different username and password combinations. Which TestNG feature should be used?

TestNG Medium
A. @AfterSuite
B. @IgnoreAll
C. @FactoryTest
D. @DataProvider

26 In TestNG, generateReport() must run only after executeTests() completes successfully. Which configuration expresses this requirement?

TestNG Medium
A. priority = "executeTests"
B. groups = "executeTests"
C. dataProvider = "executeTests"
D. 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?

Maven Medium
A. mvn clean
B. mvn test
C. mvn site
D. 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?

Maven Medium
A. runtime
B. test
C. compile
D. provided

29 A JUnit 5 test must execute the same method for the values 2, 4, and 6. Which annotation combination is appropriate?

JUnit 5 Medium
A. @Test with @Order
B. @RepeatedTest with @Tag
C. @ParameterizedTest with @ValueSource
D. @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?

JUnit 5 Medium
A. assertTrue(withdraw(200) instanceof InsufficientFundsException)
B. assertEquals(InsufficientFundsException.class, withdraw(200))
C. assertThrows(InsufficientFundsException.class, () -> withdraw(200))
D. assertDoesNotThrow(() -> withdraw(200))

31 Which Gherkin scenario correctly describes a successful login using behavior-focused steps?

Gherkin Medium
A. Given Java is installed, When Maven compiles, Then Jenkins restarts
B. Given click username, When type password, Then call the login method
C. Given the database table, When SQL runs, Then close the browser driver
D. 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?

Gherkin Medium
A. In a Background section
B. In the Feature title
C. In an Examples heading
D. In a Then comment

33 A developer changes the implementation of a calculator while keeping its public behavior unchanged. How does a JUnit regression suite help?

Introduction to JUnit Framework Medium
A. It automatically rewrites the calculator implementation
B. It verifies that existing tested behavior still passes
C. It deploys the calculator to the production server
D. It replaces all integration tests with unit tests

34 Which JUnit 5 method is correctly defined as a test?

Define a Test in JUnit Medium
A. @Test int addsNumbers() { return 2 + 3; }
B. @Test void addsNumbers(int value) { assertEquals(5, value); }
C. void @Test addsNumbers() { assertEquals(5, 2 + 3); }
D. @Test void addsNumbers() { assertEquals(5, 2 + 3); }

35 Which test method name most clearly communicates the condition and expected result?

JUnit Naming Conventions Medium
A. withdraw_whenBalanceIsInsufficient_throwsException()
B. calculate()
C. runAccountCode()
D. testMethod1()

36 A JUnit 5 suite should include every test class in the package com.example.payment. Which suite configuration is appropriate?

JUnit Test Suites Medium
A. @Test with @SelectMethods("com.example.payment")
B. @Suite with @SelectPackages("com.example.payment")
C. @TestFactory with @ImportPackage("com.example.payment")
D. @BeforeAll with @IncludePackages("com.example.payment")

37 A method isEven(8) returns true. Which JUnit assertion most directly verifies this behavior?

Example JUnit Test Medium
A. assertThrows(Boolean.class, () -> isEven(8))
B. assertTrue(isEven(8))
C. assertNull(isEven(8))
D. 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?

JUnit Code Constructs Medium
A. @BeforeEach
B. @Disabled
C. @AfterAll
D. @BeforeAll

39 A JUnit test run in Eclipse displays a red progress bar, although most tests passed. What does the red bar indicate?

Eclipse Support for JUnit Medium
A. At least one test failed or produced an error
B. Eclipse installed a newer JUnit version
C. The test class was compiled without warnings
D. All tests passed but took too long

40 A Maven-based Java project needs JUnit 5 tests to run during mvn test. Which setup is required?

Installation of JUnit Medium
A. Add JUnit only to the operating system path
B. Add a JUnit Jupiter dependency with test scope
C. Install Gherkin as the Java compiler
D. Copy Jenkins into the project's source directory

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?

Testing Tools Selection Criteria Hard
A. Select the tool with the largest number of community plugins
B. Choose the tool already known by the senior developer
C. Run a proof of concept against weighted mandatory criteria
D. Compare only execution speed using a synthetic test suite

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?

Testing Tools Selection Criteria Hard
A. Its initial procurement process will require fewer approvals
B. Its vendor can replace the team's existing defect-tracking, deployment, monitoring, and source-control systems
C. Its graphical interface contains more test-design shortcuts
D. Its tests are more portable and have lower migration risk

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?

Fundamentals of Jenkins Hard
A. The entire pipeline stops before any stage-level postcondition can execute, archive files, or update the build result
B. The stage succeeds because the junit step converts failures into warnings
C. The post block is skipped because the sh step terminated unsuccessfully
D. The stage fails, but Jenkins still attempts to publish the XML reports

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?

Fundamentals of Jenkins Hard
A. Use agent any globally and set CHROME_HOME in the UI stage
B. Use agent { label 'ui-linux' } globally for every pipeline stage
C. Use parallel branches without agent labels because Jenkins automatically detects installed software
D. Use 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?

TestNG Hard
A. Add priority values to all methods using the data provider
B. Declare the data-provider method final so that TestNG cannot replace it during concurrent execution
C. Move invocation-specific state into local variables or parameters
D. Place the test class in a single group named 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()?

TestNG Hard
A. It is skipped because a required dependency failed
B. It is retried repeatedly until the prerequisite method succeeds or the suite timeout expires
C. It runs after all independent test methods complete
D. It runs and is automatically marked as failed

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?

Maven Hard
A. Failsafe for PriceTest and Surefire for PaymentIT
B. Surefire for both classes because Maven cannot distinguish unit tests from integration tests within one module
C. Compiler Plugin for PriceTest and Surefire for PaymentIT
D. Surefire for 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?

Maven Hard
A. Test only service while resolving all dependencies remotely
B. Test service and also build its required reactor dependencies
C. Test service and also build every module that depends on it
D. Test all modules, but skip compilation and packaging for modules other than 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?

JUnit 5 Hard
A. The Vintage engine parses all source annotations and injects primitive values into Jupiter test methods
B. Java autoboxing converts each annotation string directly into an int
C. Jupiter performs a supported implicit string-to-integer conversion
D. The JVM rewrites the annotation values as integer constants at class loading

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?

JUnit 5 Hard
A. Move the method into a nested class annotated with @Nested
B. Annotate the class with @TestInstance(PER_CLASS)
C. Annotate the method with both @BeforeEach and @BeforeAll
D. Register the method through a custom display-name generator that creates one test instance for the class

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?

Gherkin Hard
A. As one scenario whose placeholders contain lists of three values
B. As a background executed once before all rows, followed by one scenario using only the final row
C. As six scenarios produced by independently combining both columns
D. As three scenario instances with row-specific substitutions

52 Which Gherkin design best preserves business readability while avoiding unnecessary coupling to a web interface?

Gherkin Hard
A. When Selenium clicks the button with id refund-submit
B. When the test calls POST /v2/refunds with status code 201 expected
C. When the customer submits a valid refund request
D. 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?

Introduction to JUnit Framework Hard
A. The JUnit Vintage test engine
B. The Maven Failsafe provider configured to reinterpret all JUnit 4 annotations as Jupiter annotations
C. The JUnit Platform launcher API
D. The Jupiter parameterized-test module

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?

Define a Test in JUnit Hard
A. The assertion fails because only the exact declared type is accepted
B. The assertion passes only when the subclass is declared as a checked exception in the test method signature
C. The assertion is skipped because exception subclasses are ambiguous
D. The assertion passes because 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?

JUnit Naming Conventions Hard
A. PaymentSpecification.java
B. PaymentTest.java
C. PaymentTestCase.java
D. TestPayment.java

56 A JUnit Platform suite is annotated with @Suite, @SelectPackages("com.example"), and @IncludeTags("fast"). What is the intended selection behavior?

JUnit Test Suites Hard
A. Discover tests in com.example and retain those tagged fast
B. Discover tests whose package is literally named fast, then include classes carrying a com.example annotation
C. Discover every classpath test and execute com.example tests before tagged tests
D. Discover only suite classes in 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?

Example JUnit Test Hard
A. Both assertions execute and their failures are reported together
B. Both failures are suppressed and the test passes because assertAll is intended only for diagnostic checks
C. Execution stops after the first failure, as with sequential assertions
D. The second assertion executes only if the first throws no exception

58 A JUnit Jupiter test calls assertTimeout(Duration.ofMillis(100), () -> service.compute()), and compute() takes 150 ms before returning normally. Which statement is correct?

JUnit Code Constructs Hard
A. The executable completes on the calling thread, then the assertion fails
B. The executable runs in a separate process that JUnit terminates after the timeout while preserving all thread-local state
C. The executable is forcibly interrupted at exactly 100 ms
D. The executable is never started because its duration is predicted in advance

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?

Eclipse Support for JUnit Hard
A. Eclipse requires all Jupiter tests to inherit from junit.framework.TestCase before its runner can discover annotations
B. The Eclipse JUnit launcher lacks compatible JUnit 5 support
C. Every Jupiter test method must be public for Eclipse discovery
D. JUnit Jupiter tests can run only through Maven and not through IDE launchers

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?

Installation of JUnit Hard
A. org.junit.vintage:junit-vintage-engine with scope provided, because Vintage contains the complete Jupiter programming and execution APIs
B. junit:junit with scope runtime
C. org.junit.jupiter:junit-jupiter with scope test
D. org.junit.platform:junit-platform-launcher with scope compile