Unit 4 - Notes
CSE320
Unit 4: Software Testing Concepts, Techniques, and Automation
1. Fundamentals of Software Testing
Definition
Software testing is the process of evaluating and verifying that a software product or application does what it is supposed to do. The benefits of testing include preventing bugs, reducing development costs, and improving performance.
Key Concepts
- Verification: "Are we building the product right?" (Static testing, reviews, walkthroughs).
- Validation: "Are we building the right product?" (Dynamic testing, executing the code).
- Defect/Bug: An error, flaw, failure, or fault in a computer program that causes it to produce an incorrect or unexpected result.
- Failure: The deviation of the software from its expected delivery or service.
Objectives of Testing
- Error Discovery: To find defects created during the development phases.
- Quality Assurance: Ensuring the software meets technical standards.
- Reliability: Gaining confidence that the system is stable and robust.
- Prevention: To prevent the migration of errors from earlier phases to later phases (which increases the cost of fixing them).
2. Functional vs. Non-Functional Testing
Functional Testing
Focuses on what the system does. It verifies the software against the functional requirements/specifications.
- Scope: User commands, data manipulation, searches, business processes, and integrations.
- Examples:
- Can a user log in with valid credentials?
- Does the "Add to Cart" button actually update the cart total?
- Does the system generate an invoice after payment?
Non-Functional Testing
Focuses on how the system performs. It verifies the non-functional attributes of the system (quality attributes).
- Scope: Performance, load, stress, scalability, security, compatibility, and usability.
- Examples:
- Does the page load within 2 seconds? (Performance)
- Can the system handle 10,000 concurrent users? (Load)
- Is the data encrypted during transmission? (Security)
3. Testing Techniques
A. Black Box Testing (Behavioral Testing)
The tester does not know the internal code structure, implementation details, or internal paths. Testing is based entirely on requirements and specifications.
- Focus: Input and Output.
- Performed by: QA Engineers, End Users.
- Advantages: Simulates user behavior; does not require coding knowledge.
B. White Box Testing (Structural/Glass Box Testing)
The tester has full knowledge of the internal structure and code of the software.
- Focus: Internal logic, code coverage (Statement, Branch, Path coverage).
- Performed by: Developers.
- Advantages: Can reveal hidden errors in code logic; helps in code optimization.
C. Equivalence Partitioning (EP)
A black-box technique that divides input data into logical groups (partitions). Data in each partition is expected to be processed in the same way.
- Goal: Reduce the total number of test cases to a manageable set.
- Example: A text field accepts age 18 to 60.
- Valid Partition: 20, 30, 50 (Any number between 18-60).
- Invalid Partition 1: 10 (Less than 18).
- Invalid Partition 2: 75 (Greater than 60).
- Testing Strategy: Pick one value from each partition.
D. Boundary Value Analysis (BVA)
A technique based on the observation that errors often occur at the boundaries of input values rather than the center. It usually follows Equivalence Partitioning.
- Strategy: Test the exact boundaries, plus one value above and one value below.
- Example: Age field 18 to 60.
- Test Values: 17 (min-1), 18 (min), 19 (min+1), 59 (max-1), 60 (max), 61 (max+1).
4. Levels of Testing
The levels of testing represent the progression of testing through the development lifecycle (V-Model).
1. Unit Testing
Testing individual components or modules of source code to determine if they are fit for use.
- By: Developers.
- Tools: JUnit, NUnit, PyTest.
- Focus: Logic within a specific function or method.
2. Integration Testing
Testing combined parts of an application to determine if they function correctly together.
- Focus: Interfaces and data flow between modules.
- Approaches:
- Big Bang: Combine all modules at once.
- Top-Down: Start from the main module and use "Stubs" for lower modules.
- Bottom-Up: Start from low-level modules and use "Drivers" to simulate higher levels.
3. System Testing
Testing the complete, integrated software product to evaluate the system's compliance with specified requirements.
- Environment: Production-like environment.
- Focus: End-to-end scenarios (Functional and Non-functional).
4. User Acceptance Testing (UAT)
Formal testing conducted to determine whether a system satisfies its acceptance criteria and to enable the user/client to determine whether to accept the system.
- Alpha Testing: Performed by users at the developer's site (controlled environment).
- Beta Testing: Performed by users at their own site (real-world environment).
5. Types of Software Testing
API Testing (Application Programming Interface)
Testing the application logic directly without using the user interface (Headless testing).
- Focus: Request/Response validation, Status codes (200 OK, 404 Not Found), JSON/XML payload structure, and data accuracy.
- Tools: Postman, SOAPUI, REST Assured.
Web Testing
Testing a web application to find bugs before deploying it to production.
- Key Areas:
- Functionality: Links, forms, cookies, database connection.
- Usability: Navigation, content checking.
- Interface: Server/Browser interactions.
- Compatibility: Cross-browser (Chrome vs. Safari) and mobile browser testing.
Mobile Testing
Testing applications developed for mobile devices.
- Types of Apps:
- Native: Built for specific OS (iOS/Android).
- Web: Mobile-optimized websites.
- Hybrid: Web apps wrapped in a native container.
- Specific Challenges: Screen resolution fragmentation, battery consumption, network switching (WiFi to 4G/5G), and interruptions (calls/SMS).
6. Automation Testing
Using software tools to execute pre-scripted tests on a software application before releasing it into production.
Selenium IDE
An integrated development environment for Selenium scripts. It is implemented as a browser extension (Chrome/Firefox).
1. Installation
- Open the Chrome or Firefox Web Store.
- Search for "Selenium IDE".
- Click "Add to Chrome" (or Firefox).
- Once installed, the Selenium icon appears in the browser toolbar.
2. Record & Playback
Selenium IDE allows "Record and Playback" functionality, making it easy for beginners to create tests without writing code.
- Step 1: Open Selenium IDE and create a new project.
- Step 2: Enter the
Base URLof the site you want to test. - Step 3: Click the REC (Record) button.
- Step 4: Manually interact with the browser (e.g., click links, type text). Selenium IDE records these actions as commands (e.g.,
open,type,click). - Step 5: Stop the recording.
- Step 6: Click Play to watch the browser automatically repeat the actions.
Introduction to Selenium WebDriver (Conceptual)
While Selenium IDE is for recording, WebDriver is a collection of APIs used to automate web application testing programmatically.
- Architecture: It communicates directly with the browser using the browser's native support (via specific drivers like ChromeDriver or GeckoDriver).
- Multi-Language Support: Tests can be written in Java, Python, C#, Ruby, etc.
- Multi-Browser Support: Chrome, Firefox, Safari, Edge.
- Advantage: Supports complex logic (loops, conditional statements, database connections) which IDE cannot handle easily.
7. Specialized Testing Basics
Performance Testing
Determines the responsiveness, throughput, reliability, and scalability of a system under a given workload.
- Load Testing: Testing system behavior under expected normal load.
- Stress Testing: Testing beyond normal operational capacity to find the breaking point.
- Spike Testing: Sudden large bursts of traffic.
- Tools: Apache JMeter, LoadRunner.
Security Testing
Ensures that the software protects data and maintains functionality as intended.
- Confidentiality: Data is accessible only to those with authority.
- Integrity: Data is not altered by unauthorized users.
- Authentication & Authorization: Verifying identity and permissions.
- Common Vulnerabilities to Test:
- SQL Injection (SQLi).
- Cross-Site Scripting (XSS).
- Broken Access Control.
8. Introduction to AI-Assisted Testing Tools
Artificial Intelligence (AI) and Machine Learning (ML) are being integrated into testing tools to solve challenges related to maintenance and coverage.
Key Capabilities
- Self-Healing Scripts: If a UI element ID changes (e.g., "SubmitBtn" becomes "BtnSubmit"), AI tools can analyze the element's attributes and automatically update the test script to prevent failure.
- Visual Regression: detecting visual bugs (layout shifts, color changes) that standard code-based assertions might miss (e.g., Applitools).
- Automatic Test Generation: AI analyzes user traffic to generate test cases based on real user behavior.
- Smart Locators: Generating robust selectors for UI elements automatically.
Popular Tools
- Applitools: Visual AI testing.
- Testim: AI-based test automation for fast authoring and stability.
- Mabl: Intelligent test automation without scripting.