Testing is a crucial aspect of software development, and Groovy offers powerful tools for ensuring your code works as expected. This collection of 30 multiple-choice questions (MCQs) covers key topics in Groovy testing, including GroovyTestCase, Spock for unit testing, mocking, stubbing, and automating tests. These MCQs are designed to help you master testing with Groovy, ensuring robust and reliable applications.
where block@Test annotation with parameters@Test annotationwhere block for multiple inputsmultiple() methodcleanup() method in Spock?
parametrize keyword@Param annotationswhere block@Test with parameters| Qno | Answer |
|---|---|
| 1 | b) To define test cases for Groovy scripts |
| 2 | a) def testMethod() { } |
| 3 | a) @Test |
| 4 | b) assert expected == actual |
| 5 | a) setUp() |
| 6 | a) tearDown() |
| 7 | c) TestCase |
| 8 | b) JUnit |
| 9 | b) Unit testing |
| 10 | c) class MyTest extends Specification { def “test method”() { } } |
| 11 | b) using the where block |
| 12 | b) setup() |
| 13 | b) expect { … } toThrow SomeException |
| 14 | b) Given-When-Then structure |
| 15 | b) Using the where block for multiple inputs |
| 16 | b) To clean up resources after a test method |
| 17 | c) assertThat |
| 18 | b) Spock runner |
| 19 | c) Using the where block |
| 20 | a) To simulate the behavior of real objects |
| 21 | a) JMock |
| 22 | c) mockFor() |
| 23 | a) Replacing method implementation with a predefined return value |
| 24 | d) thenReturn() method |
| 25 | a) verify() |
| 26 | c) when().thenThrow() |
| 27 | d) All of the above |
| 28 | b) Groovy offers dynamic typing and concise syntax for writing automated tests |
| 29 | d) All of the above |
| 30 | b) Gradle |
4o mini