Testing / Junit Interview questions
1. What is the "if statement" equivalent of Assert.
if (!<condition>) throw new AssertionError();
2. 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....
3. 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.
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....
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.
6. Difference between JUnit3 and JUnit4.
JUnit4 relies on annotations whereas JUnit3 use method names to identify tests.
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.
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....
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.
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.
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....
12. Other constraints for creating a Junit test method.
All test methods must be declared as public.
13. What is the latest version of Junit.
Junit5 published on March 21, 2016.
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....
15. What is @Test annotation?
@Test annotation is used to denote that the method is a test method.
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.
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....
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 ....
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....
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,...