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. Color of the tool logo
C. Compatibility with the project
D. Computer brand only

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

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

3 What is Jenkins mainly used for?

Fundamentals of Jenkins Easy
A. Continuous integration
B. Video playback
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. Replace the development team
D. Change the project's business requirements

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. @Verify
B. @Test
C. @Check
D. @Run

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

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

8 Which file commonly contains Maven project configuration?

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

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

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

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

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

11 What is Gherkin mainly used to write?

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

12 Which Gherkin keyword usually describes an initial condition?

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

13 What is JUnit?

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

14 What is the main purpose of a unit test?

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

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

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

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

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

17 What is the purpose of a JUnit test suite?

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

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

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

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

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

20 Which Eclipse feature can run a JUnit test class?

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

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. TestNG
B. Gherkin
C. JUnit 3
D. Jenkins

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. Number of colors in the test report
C. Length of the tool's product name
D. Compatibility with the existing technology stack

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 Maven dependency scope
D. A JUnit assertion

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

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

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

TestNG Medium
A. priority = "executeTests"
B. dependsOnMethods = "executeTests"
C. dataProvider = "executeTests"
D. groups = "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 deploy
B. mvn site
C. mvn clean
D. mvn test

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. test
B. compile
C. provided
D. runtime

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. @ParameterizedTest with @ValueSource
B. @RepeatedTest with @Tag
C. @Test with @Order
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 click username, When type password, Then call the login method
B. Given the database table, When SQL runs, Then close the browser driver
C. Given Java is installed, When Maven compiles, Then Jenkins restarts
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 Then comment
B. In the Feature title
C. In a Background section
D. In an Examples heading

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 verifies that existing tested behavior still passes
B. It automatically rewrites the calculator implementation
C. It replaces all integration tests with unit tests
D. It deploys the calculator to the production server

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

Define a Test in JUnit Medium
A. void @Test addsNumbers() { assertEquals(5, 2 + 3); }
B. @Test int addsNumbers() { return 2 + 3; }
C. @Test void addsNumbers(int value) { assertEquals(5, value); }
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. testMethod1()
B. withdraw_whenBalanceIsInsufficient_throwsException()
C. runAccountCode()
D. calculate()

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. @TestFactory with @ImportPackage("com.example.payment")
B. @Suite with @SelectPackages("com.example.payment")
C. @Test with @SelectMethods("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. assertSame(8, isEven(8))
C. assertTrue(isEven(8))
D. assertNull(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. @BeforeAll
B. @Disabled
C. @AfterAll
D. @BeforeEach

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. All tests passed but took too long
B. Eclipse installed a newer JUnit version
C. The test class was compiled without warnings
D. At least one test failed or produced an error

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

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

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. Compare only execution speed using a synthetic test suite
B. Choose the tool already known by the senior developer
C. Run a proof of concept against weighted mandatory criteria
D. Select the tool with the largest number of community plugins

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 tests are more portable and have lower migration risk
C. Its vendor can replace the team's existing defect-tracking, deployment, monitoring, and source-control systems
D. Its graphical interface contains more test-design shortcuts

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

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 parallel branches without agent labels because Jenkins automatically detects installed software
C. Use agent { label 'ui-linux' } globally for every pipeline stage
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 runs and is automatically marked as failed
B. It is retried repeatedly until the prerequisite method succeeds or the suite timeout expires
C. It is skipped because a required dependency failed
D. It runs after all independent test methods complete

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

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

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

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. Register the method through a custom display-name generator that creates one test instance for the class
B. Annotate the method with both @BeforeEach and @BeforeAll
C. Annotate the class with @TestInstance(PER_CLASS)
D. Move the method into a nested class annotated with @Nested

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

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 automation framework waits exactly 500 milliseconds, locates the third form element, and dispatches a browser click event
C. When the customer submits a valid refund request
D. When the test calls POST /v2/refunds with status code 201 expected

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 Maven Failsafe provider configured to reinterpret all JUnit 4 annotations as Jupiter annotations
B. The Jupiter parameterized-test module
C. The JUnit Vintage test engine
D. The JUnit Platform launcher API

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

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. PaymentTest.java
B. PaymentSpecification.java
C. TestPayment.java
D. PaymentTestCase.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 every classpath test and execute com.example tests before tagged tests
C. Discover tests whose package is literally named fast, then include classes carrying a com.example annotation
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. Execution stops after the first failure, as with sequential assertions
B. The second assertion executes only if the first throws no exception
C. Both assertions execute and their failures are reported together
D. Both failures are suppressed and the test passes because 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?

JUnit Code Constructs Hard
A. The executable runs in a separate process that JUnit terminates after the timeout while preserving all thread-local state
B. The executable is forcibly interrupted at exactly 100 ms
C. The executable completes on the calling thread, then the assertion fails
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. JUnit Jupiter tests can run only through Maven and not through IDE launchers
D. Every Jupiter test method must be public for Eclipse discovery

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.platform:junit-platform-launcher with scope compile
B. org.junit.vintage:junit-vintage-engine with scope provided, because Vintage contains the complete Jupiter programming and execution APIs
C. org.junit.jupiter:junit-jupiter with scope test
D. junit:junit with scope runtime