0% found this document useful (0 votes)
12 views4 pages

Group 7

Uploaded by

Ammar Khaggah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Group 7

Uploaded by

Ammar Khaggah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Topic: Testing and Continuous Integration

Writing Unit Tests and Using Testing Frameworks

1. What Are Unit Tests?

 Definition: Unit tests are automated tests written to verify the functionality of a small,
specific part of the code (a "unit").
 Purpose:
o Validate the correctness of individual functions or components.
o Catch bugs early in development.
o Facilitate refactoring by ensuring existing functionality is preserved.

2. Benefits of Writing Unit Tests

 Error Detection: Identifies issues early in the development process.


 Code Stability: Ensures new changes don’t break existing functionality.
 Documentation: Provides clear expectations of how the code should behave.
 Faster Debugging: Pinpoints the source of a problem quickly.

3. Key Practices for Writing Unit Tests

 Isolate Each Test: Avoid dependencies on other tests or external systems.


 Use Descriptive Names: Clearly describe what the test is verifying.
 Follow the AAA Pattern: Arrange, Act, Assert.
1. Arrange: Set up the initial conditions.
2. Act: Perform the action to be tested.
3. Assert: Verify the outcome.

4. Testing Frameworks Overview

A. Jest (JavaScript)

 What Is It?
o A JavaScript testing framework commonly used for front-end and back-end
applications.
o Developed by Facebook.
 Features:
o Zero-config setup for most projects.
o Built-in mocking capabilities.
o Snapshot testing for UI components.
o Detailed error reporting and performance tracking.
 Use Case: Testing React components, Node.js APIs, or any JavaScript-based logic.

B. PyTest (Python)
 What Is It?
o A versatile testing framework for Python applications.
 Features:
o Simple syntax for writing tests.
o Supports parameterized tests (run a test with multiple inputs).
o Plugins for extended functionality (e.g., pytest-django, pytest-mock).
o Auto-detection of test files and functions.
 Use Case: Testing Python scripts, web frameworks like Flask/Django, or data processing
pipelines.

5. Example Scenarios (without code)

 Testing a login function:


o Arrange: Create a mock user database.
o Act: Call the login function with valid/invalid credentials.
o Assert: Verify the output matches expectations (e.g., successful login or error).
 Testing a data processing script:
o Arrange: Provide sample data.
o Act: Run the script on the data.
o Assert: Check if the output is correct.

6. Best Practices with Testing Frameworks

 Regularly update tests as code evolves.


 Strive for high test coverage but focus on critical parts of the code.
 Use mocking to simulate external dependencies like APIs or databases.
 Integrate tests into a CI pipeline for automated execution.

Introduction to Continuous Integration (CI) tools (e.g., GitHub Actions, Travis CI)

1. What Are CI Tools?


CI tools automate the process of integrating code changes, building the application, and running
tests. They streamline development by providing a platform to detect errors early in the
development lifecycle.

2. Key Features of CI Tools

 Automation: Automatically build, test, and deploy code.


 Integration: Connect seamlessly with version control systems (e.g., GitHub, GitLab).
 Notifications: Provide real-time feedback on builds and tests.
 Scalability: Support multiple projects and configurations.

3. Popular CI Tools

A. GitHub Actions

 Overview: A CI/CD tool integrated directly into GitHub.


 Features:
o Allows you to define workflows using YAML files.
o Supports automation of testing, builds, and deployments.
o Extensive marketplace for pre-built actions.
o Free for open-source projects and offers paid plans for private repositories.
 Use Case: Automating tasks like testing a pull request or deploying code after merging.

B. Travis CI

 Overview: A cloud-based CI service widely used in open-source projects.


 Features:
o Simple configuration using a .travis.yml file.
o Supports multiple programming languages and environments.
o Offers integration with GitHub and Bitbucket.
o Provides features for parallel builds and deployment scripts.
 Use Case: Running tests across different environments, such as multiple Python or
Node.js versions.

4. Comparison of GitHub Actions and Travis CI

Feature GitHub Actions Travis CI


Integration Seamless with GitHub GitHub, Bitbucket
Ease of Use YAML-based workflows YAML-based workflows
Community Support Extensive marketplace Large user base
Feature GitHub Actions Travis CI
Cost Free for open-source Free for open-source

5. Why Use CI Tools?

 Improve code quality by automating repetitive tasks.


 Provide consistent builds and testing across environments.
 Reduce time to delivery by identifying issues early.

You might also like