Devops Module 5
Devops Module 5
Manual testing, Unit testing, JUnit in general and JUnit in particular, A JUnit example,
Automated integration testing, Docker in automated testing, Performance testing,
Automated acceptance testing, Automated GUI testing, Integrating Selenium tests in
Jenkins, JavaScript testing, Testing backend integration points, Test-driven development,
A complete test automation scenario, Manually testing our web application.
Manual Testing
Manual testing is a software testing process in which test cases are executed manually without
using any automated tool. All test cases executed by the tester manually according to the end
user's perspective. It ensures whether the application is working, as mentioned in the
requirement document or not. Test cases are planned and implemented to complete almost 100
percent of the software application. Test case reports are also generated manually.
Manual Testing is one of the most fundamental testing processes as it can find both visible and
hidden defects of the software. The difference between expected output and output, given by
the software, is defined as a defect. The developer fixed the defects and handed it to the tester
for retesting.
Manual testing is mandatory for every newly developed software before automated testing.
This testing requires great efforts and time, but it gives the surety of bug-free software. Manual
Testing requires knowledge of manual testing techniques but not of any automated testing tool.
Manual testing is essential because one of the Software testing fundamentals is "100%
automation is not possible."
Whenever an application comes into the market, and it is unstable or having a bug or issues or
creating a problem while end-users are using it.
If we don't want to face these kinds of problems, we need to perform one round of testing to
make the application bug free and stable and deliver a quality product to the client, because if
the application is bug free, the end-user will use the application more conveniently.
If the test engineer does manual testing, he/she can test the application as an end-user
perspective and get more familiar with the product, which helps them to write the correct test
cases of the application and give the quick feedback of the application.
There are various methods used for manual testing. Each technique is used according to its
testing criteria. Types of manual testing are given below:
1
White-box testing
The white box testing is done by Developer, where they check every line of a code before
giving it to the Test Engineer. Since the code is visible for the Developer during the testing,
that's why it is also known as White box testing.
The black box testing is done by the Test Engineer, where they can check the functionality of
an application or the software according to the customer /client's needs. In this, the code is not
visible while performing the testing; that's why it is known as black-box testing.
Gray box testing is a combination of white box and Black box testing. It can be performed by
a person who knew both coding and testing. And if the single person performs white box, as
well as black-box testing for the application, is known as Gray box testing.
Unit Testing
2
Objectives of Unit Testing:
To isolate a section of code.
To verify the correctness of the code.
To test every function and procedure.
To fix bugs early in the development cycle and to save costs.
To help the developers understand the code base and enable them to make changes quickly.
To help with code reuse.
3
iii. Test Runners: JUnit test runners execute test cases and report the results.
Default test runner
Custom test runners can be created if needed.
iv. Test Suites: Grouping multiple test classes together to be run as a batch.
@RunWith and @Suite annotations to create test suites.
JUnit in Particular
To illustrate JUnit in action, here is a simple example of how JUnit can be used to test a Java
class.
4
5
Explanation of the Test Class
1. Annotations:
2. Assertions:
To run the JUnit tests, you can use an IDE like Eclipse or IntelliJ IDEA, which have built-in
support for JUnit. Alternatively, you can run tests from the command line using Maven or
Gradle.
JUnit is a powerful and essential tool for Java developers, enabling them to write robust,
maintainable, and high-quality code.
6
A JUnit Example
Let's write the logic to find the maximum number for an array.
1. package com.javatpoint.logic;
2. public class Calculation {
3.
4. public static int findMax(int arr[]){
5. int max=0;
6. for(int i=1;i<arr.length;i++){
7. if(max<arr[i])
8. max=arr[i];
9. }
10. return max;
11. }
12. }
Here, we are using JUnit 4, so there is no need to inherit TestCase class. The main testing code
is written in the testFindMax() method. But we can also perform some task before and after
each test, as you can see in the given program.
7
1. package com.javatpoint.testcase;
2.
3. import static org.junit.Assert.*;
4. import com.javatpoint.logic.*;
5. import org.junit.Test;
6.
7. public class TestLogic {
8.
9. @Test
10. public void testFindMax(){
11. assertEquals(4,Calculation.findMax(new int[]{1,3,4,2}));
12. assertEquals(-1,Calculation.findMax(new int[]{-12,-1,-3,-4,-2}));
13. }
14. }
To run this example, right click on TestLogic class -> Run As -> 1Junit Test.
As you can see, when we pass the negative values, it throws AssertionError because second
time findMax() method returns 0 instead of -1. It means our program logic is incorrect.
8
Correct program logic
As you can see, program logic to find the maximum number for the given array is not correct
because it doesn't return -1 in case of negative values. The correct program logic is given below:
1. package com.javatpoint.logic;
2. public class Calculation {
3.
4. public static int findMax(int arr[]){
5. int max=arr[0];//arr[0] instead of 0
6. for(int i=1;i<arr.length;i++){
7. if(max<arr[i])
8. max=arr[i];
9. }
10. return max;
11. }
12. }
If you run the junit program again, you will see the following output.
9
Automated Integration Testing
1. Scope: It tests the interaction between integrated units or modules to ensure they
function together correctly.
2. Tools: Various tools can be used to automate integration testing, including JUnit
(with additional libraries), TestNG, Selenium, Postman, Jenkins, and Docker.
3. Types of Integration Testing:
Top-Down Integration Testing: Starts testing from the top of the control
flow and works downwards.
Bottom-Up Integration Testing: Begins testing from the bottom of the
control flow and works upwards.
Sandwich (Hybrid) Integration Testing: Combines both top-down and
bottom-up approaches.
Big Bang Integration Testing: Tests all integrated components
simultaneously, usually after all individual components are completed.
1. Identify Test Scenarios: Determine the interactions and integration points that need
to be tested.
2. Set Up the Test Environment: Configure the test environment to closely resemble
the production environment, including databases, servers, and other dependencies.
3. Create Test Cases: Write test cases that cover the identified scenarios. These should
include both normal and edge cases.
4. Automate Test Cases: Use automation tools to write scripts that execute the test
cases. Ensure these scripts can be run repeatedly with minimal manual intervention.
5. Execute Tests: Run the automated test scripts to validate the interactions between
components.
6. Analyze Results: Review the test results to identify any integration issues or failures.
7. Report and Fix Defects: Log any defects found, and work with the development
team to resolve them.
8. Rerun Tests: After fixing defects, rerun the integration tests to ensure that the issues
are resolved and no new issues have been introduced.
10
Docker in Automated Testing
Docker is a powerful tool for creating consistent and isolated test environments. By
containerizing applications and their dependencies, Docker ensures that tests run the same
way in any environment, from development to production.
1. Consistency: Ensures that tests run in the same environment, eliminating "works on
my machine" issues.
2. Isolation: Isolates test environments, preventing conflicts between dependencies.
3. Scalability: Easily scales testing environments by spinning up multiple containers.
4. Portability: Runs on any machine with Docker installed, ensuring the same
environment across different stages of development.
Performance Testing
Performance testing evaluates the speed, responsiveness, and stability of an application under
various conditions. Tools like Apache JMeter, Gatling, and Locust are commonly used for
this purpose.
Key Aspects
1. Load Testing: Simulates multiple users to test the application’s behavior under
normal and peak loads.
2. Stress Testing: Tests the application under extreme conditions to see how it handles
high traffic and data processing.
3. Scalability Testing: Checks the application’s ability to scale up or down based on
demand.
4. Endurance Testing: Ensures the application can handle prolonged use.
Automated acceptance testing verifies that the application meets business requirements and
user needs. Tools like Cucumber and FitNesse are used to write tests in a language that
business stakeholders can understand.
Key Aspects
11
3. Automated Scripts: Converts acceptance criteria into automated test scripts that can
be run continuously.
Automated GUI testing verifies the user interface and user experience of an application.
Tools like Selenium, TestComplete, and QTP are used for this purpose.
Key Aspects
1. Cross-Browser Testing: Ensures the application works correctly across different web
browsers.
2. Interaction Testing: Simulates user interactions with the application’s UI elements.
3. Visual Testing: Checks the visual appearance of the application to ensure it looks as
expected.
Jenkins is a popular continuous integration and continuous delivery (CI/CD) tool that can
automate the execution of Selenium tests.
JavaScript Testing
JavaScript testing ensures the correctness of JavaScript code and its behavior in a web
application. Tools like Jest, Mocha, and Jasmine are commonly used for this purpose.
Key Aspects
12
Testing backend integration points
Testing backend integration points is essential to ensure that various components of the
backend system communicate and function together as expected. This type of testing
typically involves verifying interactions between different services, databases, and external
APIs. Automated testing of backend integration points helps maintain system reliability,
performance, and scalability.
1. JUnit: Commonly used for unit and integration testing in Java applications.
2. Spring Test: Provides support for integration testing in Spring applications.
3. TestContainers: Allows running database and other service containers for integration
tests.
4. Postman: Can be used for API testing and automation.
5. REST Assured: A Java library for testing REST APIs.
6. Mockito: For mocking dependencies in unit and integration tests.
1. Red: Write a test for a new feature or functionality, which will initially fail (since the
feature is not implemented yet).
2. Green: Write the minimum amount of code required to pass the test.
3. Refactor: Refactor the code to improve its structure and design while ensuring that it
still passes the test.
13
Benefits of TDD
1. Improved Code Quality: Writing tests first helps ensure that the code is designed to
meet the requirements from the outset.
2. Early Bug Detection: Bugs are detected early in the development process, reducing
the cost and effort required to fix them.
3. Better Design: TDD encourages writing small, modular, and testable code, leading to
better software design.
4. Documentation: Tests serve as a form of documentation, providing examples of how
the code is intended to be used.
TDD Workflow
Creating a complete test automation scenario involves several steps, including setting up the
environment, writing test scripts, executing tests, and integrating with CI/CD pipelines for
continuous testing. Below, I outline a comprehensive scenario that involves automating tests
for a web application using Selenium for GUI testing, JUnit for backend testing, and
integrating these tests with Jenkins for continuous integration.
14
2. Project Structure
automation-project
|-- src
| |-- main
| | |-- java
| |-- test
| |-- java
| |-- tests
| |-- BackendTest.java
| |-- GuiTest.java
|-- pom.xml
3. Configure pom.xml
Add dependencies for Selenium, JUnit, and any other required libraries.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>automation-project</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- JUnit for testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
15
<version>7.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
4. Writing Tests
@Test
public void testAddition() {
int a = 5;
int b = 3;
int result = add(a, b);
assertEquals(8, result);
}
16
GUI Test (Selenium)
package tests;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
driver = new ChromeDriver();
}
@Test
public void testLogin() {
driver.get("http://example.com/login");
driver.findElement(By.id("username")).sendKeys("testuser");
driver.findElement(By.id("password")).sendKeys("password");
driver.findElement(By.id("loginButton")).click();
@After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
17
5. Integrating with Jenkins
1. Install Jenkins.
2. Install the following plugins:
o Maven Integration Plugin
o JUnit Plugin
o Selenium Plugin
clean test
Manual testing of a web application involves several steps to ensure that the application is
functioning as expected. Here's a detailed guide on how to manually test a web application:
18
Manual Testing of Our Web Application
1. Preparation
Ensure that you have the necessary hardware, software, and network configurations.
Prepare the required test data.
2. Test Planning
Create detailed test cases with clear steps, expected results, and test data.
Ensure that test cases cover positive and negative scenarios.
3. Execution
19
3.3. Performance Testing
Load Testing: Test how the application performs under a specific load (e.g., number
of users).
Stress Testing: Test the application's behavior under extreme conditions (e.g., heavy
load, high traffic).
Test the application for vulnerabilities such as SQL injection, cross-site scripting
(XSS), and cross-site request forgery (CSRF).
Ensure that sensitive data is protected and secure.
4. Defect Reporting
Use a defect tracking tool (e.g., JIRA, Bugzilla) to manage and track the status of
defects.
Communicate with developers and other stakeholders to ensure defects are resolved.
5. Regression Testing
Verify that fixed defects are resolved and the application functions as expected.
Ensure that new changes have not introduced new defects.
Test the entire application or affected areas to ensure that recent changes have not
negatively impacted existing functionality.
Ensure that all planned test cases have been executed and all key features have been
tested.
20
Review any areas that were not covered and assess the risk.
Summarize the test results, including the number of test cases executed, passed,
failed, and any defects found.
Provide recommendations and conclusions based on the testing results.
21
Tools and Techniques
Browser Developer Tools: Use browser developer tools to inspect elements, view
console logs, and debug issues.
Screenshot Tools: Use tools like Snipping Tool, Lightshot, or built-in browser
screenshot features to capture evidence of issues.
Defect Tracking Tools: Use tools like JIRA, Bugzilla, or Redmine to log and manage
defects.
Collaboration Tools: Use tools like Slack, Microsoft Teams, or email to
communicate with team members and stakeholders.
Answer: Manual testing involves executing test cases without automated tools to validate that
software behaves as expected. Testers manually check the application's functionalities, user
interface, and overall usability by following predefined test scenarios. The importance of
manual testing lies in its ability to uncover issues that automated tests may miss, especially in
areas like user experience and visual aspects. Manual testing is crucial during the initial stages
of development, where requirements may evolve, and immediate feedback is necessary. It
allows testers to use their intuition and experience to evaluate the application, ensuring that the
final product meets user needs.
Answer: Unit testing is a software testing technique where individual components or functions
of a program are tested in isolation to ensure they work as intended. Each test typically focuses
on a small piece of functionality, such as a method or a function. The benefits of unit testing
include early bug detection, as issues can be identified and fixed at the component level, thus
reducing the cost of fixing defects later in the development process. It also promotes better
design and refactoring since developers are encouraged to write modular code. Additionally,
unit tests serve as documentation, helping new developers understand the system’s
functionality.
Answer: JUnit is a widely-used testing framework for Java that supports the development of
unit tests. It provides annotations to identify test methods, setup methods, and assertions to
verify expected outcomes. JUnit helps developers write repeatable tests efficiently, improving
code quality and reliability. Developers use JUnit to create test cases that are executed
automatically, providing immediate feedback during development. The framework also
integrates seamlessly with build tools like Maven and Gradle, enabling continuous integration
22
workflows. Using JUnit, teams can ensure that their code is thoroughly tested, promoting a
culture of quality in software development.
@Test
public void testAddition() {
Calculator calculator = new Calculator();
int result = calculator.add(5, 3);
assertEquals(8, result, "5 + 3 should equal 8");
}
}
In this example, the CalculatorTest class contains a test method testAddition, which checks if the
add method of the Calculator class returns the expected result when adding 5 and 3. The
assertEquals method verifies that the actual result matches the expected result, promoting reliable
unit testing.
Answer: Automated integration testing focuses on verifying the interactions between different
modules or components of an application. This type of testing ensures that integrated parts of
the application work together as intended. It is typically performed after unit tests and before
system tests in the testing hierarchy. Automated integration tests can be written using
frameworks like JUnit or TestNG, and tools like Postman or REST Assured for API testing.
Developers create test cases that simulate interactions between components, validating that
data flows correctly and that the system behaves as expected when modules interact.
23
7. What is Performance Testing, and what tools are commonly used?
Answer: Performance testing assesses how a system performs under various conditions, such
as load, stress, and endurance. Its primary goal is to identify bottlenecks and ensure that the
application meets performance criteria before release. Common types include load testing
(measuring response under expected loads) and stress testing (evaluating behavior under
extreme conditions). Popular tools for performance testing include JMeter, LoadRunner, and
Gatling. These tools simulate multiple users interacting with the application, measuring
response times, throughput, and resource utilization to ensure the system can handle anticipated
traffic and performance requirements.
Answer: Automated GUI testing involves using automated tools to validate the graphical user
interface of an application to ensure it functions as intended. This type of testing checks for UI
consistency, functionality, and user interactions, such as clicking buttons and entering data.
Automated GUI testing is essential because it significantly reduces the time required for
regression testing, ensures consistent testing across multiple environments, and allows for
frequent validation of UI components during development. Tools like Selenium, Cypress, and
TestComplete are commonly used for automating GUI tests, enabling developers to maintain
high-quality standards while delivering software quickly.
Answer: Integrating Selenium tests into a Jenkins pipeline involves several steps to ensure
automated testing within the CI/CD process. First, create a Jenkins job that points to your
project's repository. In the job configuration, specify the build trigger (e.g., on every push or
on a schedule). In the build step, use Maven or Gradle to execute the tests, typically with
commands like mvn clean test or gradle test. You can also set up post-build actions to publish test
results, enabling visibility into the test outcomes within Jenkins. This integration ensures that
Selenium tests are run automatically, providing immediate feedback on code changes and
maintaining high software quality.
10. What is Test-Driven Development (TDD), and what are its core principles?
24