JUnit Interview Questions- Part 4
JUnit isn’t just for developers—it’s a powerful ally for QA engineers and automation testers too. This guide dives into JUnit interview questions and answers from a quality assurance perspective. Learn how to leverage JUnit for automated regression testing, integrate it with Selenium, and use assertions to validate UI and backend logic.
We explore test-driven development (TDD) principles, mocking frameworks like Mockito, and how JUnit fits into CI/CD pipelines. If you’re a QA professional looking to expand your automation toolkit or preparing for a hybrid QA/Dev role, this resource will help you speak confidently about your testing approach. It’s not just about writing tests—it’s about designing them to catch what others miss.
Answer:
There are four testing levels in the software development lifecycle that provides different purposes, such as:
- Unit testing:Unit is the smallest testable portion of an application or a system that can be liked, compiled, executed, and loaded. This testing helps to test each module individually. The central purpose of this testing method is to test each part of the software by separating it. It checks whether the components are fulfilling functionalities or not. The developers perform this testing.
- Integration testing:Integration simply means combining. In this phase of testing, different software modules are combined and tested to ensure that the integrated system is ready for system testing. Integration testing checks the data flow from a module to another.
- System testing:System testing is performed on a complete integrated system. It enables you to check a system’s compliance as per the requirements. It tests the entire interaction of components. System testing includes performance, load, reliability, and security testing. It is most often the final test to verify if the system has met the specifications. It evaluates both functional & non-functional needs for testing.
- Acceptance testing: This type of testing is conducted to determine if the requirements of a particular contract or specification are met according to its delivery. Acceptance testing is done through the users or customers. However, other stockholders can be involved in this process.
Answer:
A test case means a set of actions executed to verify a particular functionality or feature of the software application. It contains test data, preconditions, test steps, and postconditions developed for specific test scenarios to verify the requirements. The test case includes specific conditions or variables, using which a testing engineer can compare the expected and actual results to determine if a software product is functioning as per the customer’s requirements.
Answer:
Verification in Software Testing- It is a process of checking designs, documents, codes, and programs to verify if the software has been built as per the requirements. The main goal of the verification process is to ensure the software application’s quality, design, architecture, etc. The verification process involves activities like walk-throughs, reviews, and inspections.
Validation in Software Testing- It is a dynamic process of testing and validating if the software product meets customers’ exact requirements. This process helps to ensure that the software meets the desired use in an appropriate environment. The validation process involves integration testing, unit testing, user acceptance testing, and system testing.
Answer:
Usability testing means a non-functional testing technique that measures how easily the end-users can use a system. It is difficult to evaluate but can be measured based on the following parameters:
- Level of skills required to use or learn the software. It should maintain a balance for both novice and expert users.
- The time needed to get accustomed to using the software.
- To check the increase in user productivity (if any).
- Evaluation of the user’s attitude towards using the software.
Answer:
In any project, the acceptance document is usually prepared with the following inputs:
- Requirement document: This document specifies what precisely is needed in a project from the customer’s perspective.
- Input from customers: It includes informal talks, discussions, emails, etc.
- Project plan: The project manager prepares the plan, which serves as a good input to finalize your acceptance test.
Answer:
The code coverage tools use one or more criteria to determine how a code was exercised. Below are some common metrics mentioned in the coverage reports:
- Function coverage: How many functions in a program defined have been called.
- Statement coverage: How many statements in a program have been executed.
- Branches coverage: How many control structure branches have been executed.
- Condition coverage: How many Boolean sub-expressions have been tested for a true/false value.
- Line coverage: How many source code lines have been tested.
Answer:
Selenium is the most preferred tool for automation testing because it provides the following benefits:
- Transparency: It ensures transparency and agility across cross-functional teams of SDLC processes (quality assurance, developers, clients, operations, and management).
- Platform Independent: Selenium discards the software tester’s time in writing the test scripts for each platform to be tested. Also, it follows the principle of writing a test script and runs on any platform.
- Quickens TTD and TTM: In manual testing, the testing is very uncertain and painful, due to which the time and product delivery to market schedules are missed. It increases the cost of the overall project. However, Selenium prevents testers from writing the test script for each platform. This, in turn, saves time and avoids the regression testing process. It optimizes the testing time and quickens the TTD and TTM.
- Facilitate Continuous Integration Efforts: Continuous Integration and Continuous Delivery (CI/CD) are modern agile-enablers of the software development process. As Selenium automates the overall test process, it acts as a catalyst to nurture the organization’s efforts to successfully implement Continuous Integration practice.
- Visibility in End-to-End Testing: In the testing of the end-to-end application, Selenium renders great visibility.
- Reduces Turnaround Time: Selenium facilitates testing teams to automatically run multiple test cases simultaneously on multiple browsers. It reduces the turnaround time by ensuring extreme testing quality.
- Integration With Other Tools: Selenium with Java is popular like other jars such as Sikuli, Appium, ExtentReports, etc. Selenium provides flexibility for testers to get integrated with the jars to extend its functionalities to the new frontiers:
- Selenium integration with “ExtentReports” can generate reports and graphs to provide insights on the client’s testing status.
- Integrating Selenium with “Sikuli” can test web applications having images and videos.
- Testing web applications on iOS or Android platforms can be done by integrating Selenium with Appium.
Answer:
Selenium has the following two components:
Selenium IDE (Integrated Development Environment)- Selenium IDE is mainly a Firefox plugin. It is the simplest framework in the Selenium Suite. It enables us to record and playback the scripts. If you want to create scripts with Selenium IDE, you need to use Selenium WebDriver or Selenium RC to write more robust and advanced test cases. In IDE, the test case execution is slow, and the report generation step for the test cases is not good as other components. It doesn’t support test case execution in remote or parallel execution.
Selenium RC- It is also known as Selenium 1. The Selenium RC was the main Selenium project for a long period before the WebDriver merge brought Selenium 2. It mainly relies on JavaScript for automation and supports other languages like PHP, Ruby, Python, C#, Perl, and Java. Besides, it also supports almost every
JavaScript commands to drive a browser. It bypasses the problems with subtle differences between JavaScript and native commands, including security restrictions.
Selenium GRID- Selenium Grid means a server that enables tests to use web browser instances running on the remote machines. With Selenium Grid, a server acts as the hub. Tests contact the hub to attain access to the browser instances. The hub possesses a list of servers that renders access to browser instances, and lets tests use those instances. Selenium Grid helps to run tests in parallel on multiple machines and centrally manages different browser versions and configurations.
Answer:
Selenium supports the following types of locators:
- ClassName: This operator uses a class attribute to find an object.
- CSS Selector:CSS is utilized to create the style rules for web pages, and it can also be used to identify a web element.
- ID:It is similar to a class, and we can also identify elements through the ‘ID’ attribute.
- linkText: Text used in the hyperlinks can also locate the elements.
- Name: The name attribute can also identify an element.
- PartialLinkText: Any part of a text in the link can also identify the element.
- TagName: We can also utilize a tag to locate the elements.
- Xpath: Xpath is the language utilized to query an XML document. The same can uniquely identify a web element on any page.
Answer:
The key difference between an absolute and a relative path is that an absolute path specifies a location from the root directory, but a relative path is mainly related to the current directory.
- Another difference between these two pathways is that an absolute pathway starts with a delimiting character (“/”) whereas a relative pathway begins with characters like (“..”) but it never begins with (“/”) or (“\”).
- The absolute pathway is used when a link navigates to some content on another website, and the relative pathway is used when linking something on the same website.
- An absolute path is also known as a full-pathway whereas a relative path is also known as a partial pathway or non-absolute path.
- An absolute pathway uses an absolute URL to navigate to the pages beyond a single domain. In constant, a relative pathway uses a relative URL that navigates to pages in the same domain only.
Answer:
There is an extensive list of Selenium Exceptions in the Selenium documentation. Below are some standard exceptions that occur when running a test:
- ElementNotVisibleException: Despite an element being present in the DOM (Document Object Model), it is not visible & cannot be interactive.
- ElementNotSelectableException: An element that is disabled cannot be selected or clicked despite being presented in the DOM.
- NoSuchElementException: Webdriver cannot determine the elements during the runtime; here, the FindBy method cannot find a particular component.
- NoSuchFrameException: Webdriver tries to switch to an invalid frame, which is unavailable
- NoAlertPresentException: Webdriver attempts to switch to an invalid alert, which is unavailable
- NoSuchWindowException: Webdriver tries to switch to the invalid window, which is unavailable
- StaleElementReferenceException: The referenced element is no longer exist on the Document Object Model DOM page.
- SessionNotFoundException: Webdriver is acting immediately after you quit the browser.
- TimeoutException: The command did not complete in a particular time. It is specifically encountered when working with waits.
- WebDriverException: Webdriver is immediately acting after ‘closing’ the browser.
Answer:
You can use Selenium Grid when you want to do the following:
- Run your tests against different machines, browsers, and operating systems, all at once- It will ensure that an application you are testing is completely compatible with a wide range of browsers-Operating Systems.
- Save time in the test suite execution- If you set up a Selenium Grid to run 4 tests simultaneously, you can finish the entire suite around 4 times faster.
Answer:
Regression testing – It is a type of testing performed by QA after some changes were made to the system to ensure all its old processes still work as expected and provide the required results. The scope of regression testing mainly depends on a project’s requirements and how big the changes were done. For trivial changes, you can even avoid such testing, but for some massive new features that may indirectly affect the existing ones, you will need to dedicate some time to regression testing to ensure that everything works as expected. How deep a regression testing should be performed also differs from one project to another, and it also depends on the severity of changes. Regression testing has only one consistent; tests are focused on the already existing and not the new processes on the project. It is better to automize the regression tests as it will improve the project’s quality and save an ample amount of time for the QA team that may spend more time on the detailed testing of new features.
Confirmation testing – This type of testing is performed by QA for processes that didn’t show an expected result after the previous tests, so additional changes were made for them. The scope of confirmation testing in most cases is unchangeable and consistent. You should check the result of changes using all the inputs, environments, and data used when the fixed issue was previously noticed.
Answer:
Boundary value analysis is a widely used case design technique for black-box testing. It is used to test boundary values as an input value near a boundary has higher chances of error. When we do testing, through boundary value analysis, the tester focuses on, while entering boundary value, whether the software is producing correct output or not. Boundary values contain a variable’s upper and lower limits. For instance, age is a function variable, and its minimum value is 18 while the maximum value is 30; both 18 & 30, in this case, will be considered the boundary values.
Answer:
To estimate your project, you need to consider the following points:
- Divide the entire project into small tasks;
- Allocate each task to different team members;
- Estimate the efforts needed to complete each task;
- Lastly, validate the estimation.
Answer:
Black box test cases are written first, and after that, white box test cases are written. To write the black box test cases, we need the design and requirement document or project plan. All documents are readily available at the initial stage of a project. However, White box test cases cannot be started in the initial stage of a project as they need more architecture clarity which is not accessible during the start of a project. So, white box test cases are written after the black box test cases.
Answer:
The following are the basic components of defect report format:
- Module Name
- Project Name
- Defect detected by
- Defect detected on
- Snapshot of the defect
- Defect ID and Name
- Defect resolved on
- Defect resolved by
- Priority and Severity status
Answer:
A test fixture is referred to as the regulated state of objects used as a platform for running the tests. The primary objective is to ensure that there is a known climate wherein the development tests can run. Some examples of text fixture are as follows:
- Copying the fixed, known set of files
- Preparing input data and the creation of fake or mock objects
- Assessing database with fixed and known sets of data
Note: If a group of tests shares the same fittings, you need to write a different setup code. However, if the group of assessments needs a different test fixture, you can write the code along with the test procedure. In that manner, you can create the best accessory related to the test.
Answer:
The TestSuite is used to bundle and run some unit test cases together. In JUnit, both @Suite and @RunWith annotations are used to run the suite tests.
Answer:
As per the design, a Test instances tree is built at the first pass while the test execution is done at the second pass. Thus, a test runner holds solid references to all the test instances for the duration of test execution. For instance, if a test runs for very long along with many Test instances, none of the tests may get garbage collected until an entire test run completion. Therefore, you need to free up resources programmatically that is allocated for running the test. If you explicitly set the objects to null in a tearDown() method, it will allow it to be garbage collected before am entire test run completion.