Java8 Qualis Interview Question-Answer Part – 1

Q.1 Code Snippet

@BeforeAll public void ResetCounterBeforeTestcase() throws Exception { counter = 0; }

While executing a test class, how many times the given section of code will get executed if there are three test methods defined in the class?

       A. Three times

       B. Never

       C. Two times

       D. Once

Ans : Once

Q.2 Which of the following annotation causes that method run after each test methods?

       A. @AfterEach

       B. @AfterAll

       C. @BeforeAll

       D. @test

Ans : @AfterEach

Q.3 Which of the following is not an optional parameter defined for the @Test annotation?

       A. timeout

       B. threadcount

       C. expected

       D. None of the options

Ans : threadcount

Q.4 Which of the following is true about JUnit?

       A. JUnit provides test fixtures to share the common test data

       B. JUnit is a testing framework for Java

       C. JUnit is an open source framework

       D. All the options

Ans : All the options

Q.5 Which of the following method asserts that both the objects refer to the same object?

       A. assertSame(obj1,obj2)

       B. assertnotSame(obj1,obj2)

       C. assertFalse(obj1==obj2)

       D. assertEquals(obj1=obj2)

Ans : assertSame(obj1,obj2)

Q.6 Logical collection of test classes can be bundled together to form a __________.

       A. Runner

       B. Suite

       C. Filter

       D. Fixture

Ans : Suite

Q.7 Which JUnit annotation allows you to define order of execution for the test methods?

       A. @FixMethodOrder

       B. @Rule

       C. @DefineOrder

       D. @Ignore

Ans : @FixMethodOrder

Q.8 Which sorter methods will execute the text methods in the lexicographic order of their names?

       A. MethodSorters.NAME_ASCENDING

       B. MethodSorters.LEXICOGRAPHIC_SORTER

       C. MethodSorters.Default

       D. MethodSorters.JVM

Ans : MethodSorters.NAME_ASCENDING

Q.9 For any JUnit method, the return type should be __________.

       A. Void

       B. Object

       C. String

       D. Null

Ans : Void

Q.10 Test cases are executed with a fixed state of object which can be a baseline for running tests to ensure the results are repeatable, such object are called __________.

       A. Fixture

       B. Froster

       C. StableSet

       D. Frontier

Ans : Fixture

Q.11 Which of the following can Mockito mock?

       A. Static methods

       B. Enum

       C. Public methods

       D. Final methods

Ans : Public methods

Q.12 JUnit tests will be executed in the same order in which they are written.

       A. True

       B. False

Ans : False

Q.13 Mockito can mock private methods.

       A. True

       B. False

Ans : False

Q.14 Which among the following is a test double?

       A. A fake object

       B. A dummy object

       C. Mock object

       D. All of these

Ans : All of these

Q.15 Which among the following test double is used to replace a target function with pre programmed method directing to specific path? Choose the correct option from below list

       A. Mocks

       B. Stub

       C. Spie

       D. Dummies

Ans : Stub

Q.16 Mockito can inject mocks via ________.

       A. Predictive Injection

       B. Constructor Injection

       C. Desructive Injection

       D. None of the options

Ans : Constructor Injection

Q.17 Mockito framework offers _______ to compute on-the-fly results.

       A. Stubbing

       B. Callbacks

       C. AdaptiveResponse

       D. Setbacks

Ans : Callbacks

Q.18 Mockito can throw an exception using which of the following?

       A. when().thenReturn()

       B. when().thenAnswer()

       C. doWhen().thenThrow()

       D. when().thenThrow()

Ans : when().thenThrow()

Q.19 MockMvc tests the expected response details that are configured using _______ calls after performing a request.

       A. .andGet()

       B. .perform()

       C. .andDo(print())

       D. .andExpect()

Ans : .andExpect()

Q.20 _____ is a class level annotation to indicate the Application context for the test that will be Web application context.

       A. @ServersideConfiguration

       B. @JsonConfiguration

       C. @WebAppConfiguration

       D. @RestApplication

Ans : @WebAppConfiguration

Q.21 _____ forms the integral part of Spring Testing framework.

       A. PowerMock

       B. Mockito

       C. MockMVC

       D. PowerMVC

Ans : MockMVC

Q.22 Integration of JUnit and the Spring Test context framework is done by _____ runner.

       A. Cucumber Runner

       B. MockitoJUnitRunner

       C. SpringJUnit4ClassRunner

       D. HierarchicalContextRunner

Ans : SpringJUnit4ClassRunner

Q.23 MockMvc is used to mock the entire Spring MVC infrastructure. True or False.

       A. True

       B. False

Ans : False

Leave a Comment