Testing
Testing
NO: 8
DATE: TESTING THE SOFTWARE SYSTEM
Aim:
To test the software system for all the scenarios identified as per the use case diagram.
Testing:
Testing is a critical phase in the software development lifecycle, aimed at ensuring that a
software application or system performs as expected and meets its requirements. It involves
systematically identifying, detecting, and resolving defects or inconsistencies in the code. By
doing so, testing helps improve the quality, reliability, and performance of the software,
ensuring it aligns with user expectations and business goals.
Purpose of Testing:
The primary purpose of testing is to:
1. Validate functionality: Ensure that the software meets its functional and non-
functional requirements.
2. Detect defects: Identify errors, bugs, or unexpected behaviours in the code.
3. Ensure reliability: Verify that the software performs consistently under various
conditions.
4. Improve performance: Test the software to optimize its speed, scalability, and
responsiveness.
5. Enhance user satisfaction: Ensure the software is user-friendly, secure, and aligned
with end-user needs.
JUnit Framework:
JUnit is a widely-used testing framework for Java, primarily designed for unit testing Java
applications. It is part of the xUnit family of testing frameworks and provides a simple and
effective way to write and execute tests. Key features of JUnit include:
• Annotation-Based Testing: Annotations like @Test, @BeforeEach, and
@AfterEach manage test lifecycles.
• IDE Integration: Compatible with IntelliJ IDEA, Eclipse, and NetBeans for
easy test execution.
• Assertions: Provides methods like assertEquals, assertTrue, and assertThrows for
result validation.
• Parameterized Tests: Allows running tests with different input values for broader
coverage.
• Integration with Build Tools: Works seamlessly with Maven and Gradle for
automated testing.
• Exception Testing: Verifies expected exceptions using assertThrows. Support for
Node.js and browser environments.
• Support for Mocking Frameworks: Works seamlessly with mocking libraries like
Mockito for creating mock objects and isolating dependencies.
Installation:
1. Add JUnit Dependency (Maven): Include the following dependency in your
pom.xml:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
2. Configure Test Plugin (Maven): Ensure the Maven Surefire plugin is configured to
run tests:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.1</version>
</plugin>
</plugins>
</build>
3. Run Tests: mvn test
// DTOTests.java
package com.inventory.dto;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class DTOTests {
@Test
public void testDTOValidation() {
SupplierDTO dto = new SupplierDTO("ValidSupplier", 1000);
assertTrue(dto.isValid(), "DTO should be valid"); }
@Test
public void testInvalidDTO() {
ProductDTO dto = new ProductDTO("InvalidProduct", -10); // Invalid price
assertFalse(dto.isValid(), "DTO should not be valid with negative price"); }}
Description Allotted Marks Obtained Marks
Preparation 20
Design/Implementation 20
Viva 15
Output 10
Record 10
Total 75
RESULT:
Thus, the software is tested for all the scenarios identified as per the use case diagram.