Prev Next

Testing / Junit Interview questions

1. What is unit testing?

Unit Testing refers to the process of verifying/testing the individual components, functional units of any application (methods/procedures/classes) that contains business logic, reusable components and ensure the working of the functional units. Unit testing can be done automatically or manual.

Read full answer

2. What is the "if statement" equivalent of Assert.

if (!) throw new AssertionError();

Read full answer

3. What is Java "assert" statement?

The assert keyword is used in assert statement which is introduced in Java 1.4. It helps the code developers to test assumptions and to assert if the outcome is as expected that enables detecting bug and fixing it. public class AssertExample { public static void main (String [] args) { assert 0 >...

Read full answer

4. Differentiate Manual vs Automated Unit testing.

Manual testing involves the preparation of test cases and those are tested by developers. Automated Unit testing: Test cases are executed by automation tools such as JUnit. Automated Unit testing is preferred over manual, as Automated test helps covering all the scenario/test any time required. A...

Read full answer

5. Unit Test Case.

refers to the combination of possible inputs to the unit and desired output of based on the input, that helps to certify the functionality of the individual unit. Unit test cases are prepared and used by Developers.

Read full answer

6. Difference between JUnit3 and JUnit4.

JUnit4 relies on annotations whereas JUnit3 use method names to identify tests.

Read full answer

7. What is JUNIT?

Junit is an open source testing framework developed for unit testing Java based applications. An API that enables developer to writes and executed repeatable automated test cases.

Read full answer

8. Advantages of using Junit.

Enables writing test cases while developing the software that helps test early and detect issues. Ensure the functionality is performing as expected every time the code is modified by the use of repeatable automated test cases. supported by all IDE including Eclipse, Netbeans, RAD etc. integrates...

Read full answer

9. How will you create a JUnit Test Class?

in JUnit3, Java classes should extend junit.framework.TestCase . JUnit 4, any public class with a no arg public constructor can behave as a JUnit test class.

Read full answer

10. How do you create a JUnit test Method?

in JUnit3, test methods should follow the naming convention as the pattern test for e.g. testCompareMethod. In Junit 4, test methods would be just annotated with @Test.

Read full answer

11. Can a JUnit test method have a return type other than void?

All the JUnit test methods should have a void return type. otherwise it will be ignored. If the return type of a test method is changed, it would not be considered as a test method and would be ignored during execution of tests.

Read full answer

12. Other constraints for creating a Junit test method.

All test methods must be declared as public.

Read full answer

13. What is the latest version of Junit.

Junit5 published on March 21, 2016.

Read full answer

14. Differentiate JUnit 4 and TestNG.

in Java, JUnit 4 and TestNG are popular unit test framework and look very similar in functionality. TestNG supports annotation @BeforeSuite that enables running a method before even the suite runs whereas Junit 4 does not support. TestNG supports @AfterSuite that enables running a method after th...

Read full answer

15. What is @Test annotation?

@Test annotation is used to denote that the method is a test method.

Read full answer

16. Explain @Ignore.

@Ignore annotation ignore the annotated test method to be executed. It is used when the test method is incomplete or needed to be not executed.

Read full answer

17. What are the annotations used in Junit4?

@Test. The Test annotation indicates that the public void method to which it is attached can be run as a test case. @Before. The Before annotation indicates that this method must be executed before each test in the class, so as to execute some preconditions necessary for the test. @BeforeClass. T...

Read full answer

18. Exception testing (Difference between Junit 3 and Junit 4)

Junit 3 public void testGetElement () { try { (new ArrayList()).get(0) ; fail("The test should have failed") ; } catch ( NullPointerException e ) { assertTrue("Sanity check", true) ; } } Junit 4 Junit 4.x @Test (expected = IndexOutOfBoundsException . class) public void testGetElement() { (new Arr...

Read full answer

19. Difference between @Before and @BeforeClass.

@Before public void runBeforeEachTest() This method gets executed before each test execution in the current Test class. This method usually helps initialize the resources required for the action test to execute. It is executed everytime before running a test method. @BeforeClass public static voi...

Read full answer

20. Differentiate @After and @AfterClass.

@After public void runAfterEachTest() This method gets executed after every test and it is used to clean up the test and temporary data that are used by test. @AfterClass public static void runAfterAllTheTest() This method gets executed at the end, when all the tests have completed execution and ...

Read full answer

«
»

Comments & Discussions