Simplifying Database Tests with DreamFactory

DreamFactory can effortlessly create secure internal REST APIs in a matter of minutes, and offers a comprehensive database testing solution. With DreamFactory, you can validate your databases with ease, ensuring they meet your application's requirements and deliver impeccable performance. In this article we’ll cover how DreamFactory simplifies the database testing process.

Here's the key things to know about simplifying database tests with DreamFactory:

  • Database testing is a critical process to ensure database accuracy, reliability, and security in various applications.
  • It involves verifying data consistency between the database and the user interface, ensuring tight connections between the front end and back end.
  • Database testing validates the ACID properties of transactions (Atomicity, Consistency, Isolation, and Durability) to ensure data integrity and stability.
  • It ensures that the latest data is consistently displayed across different parts of an application, preventing discrepancies.
  • Database testing also confirms that complex business rules, constraints, triggers, and stored procedures are correctly implemented within the database to support business logic.

Table of Contents

What is Database Testing?

The database plays a vital role as the silent powerhouse behind the scenes. Whether it's a website, a mobile app, or complex software like those used in healthcare, finance, or retail, databases are always at work in the background.

Database testing is the process of rigorously evaluating these databases to ensure their accuracy, reliability, and security. It's about making sure that the data within these databases is not just present but also correct and accessible.

Why is Database Testing Important

  • Data Mapping: Database testing involves verifying that the information stored in the database aligns consistently with what's displayed on the user interface. It's like making sure the threads connecting the front end to the back end are tightly woven.
  • ACID Properties Validation: Every transaction a database performs should adhere to four critical properties: Atomicity, Consistency, Isolation, and Durability. In simple terms, this means that transactions should either succeed entirely or fail entirely, always result in a valid database state, provide consistent results whether executed together or separately, and remain stable even in the face of external issues like power outages.
  • Data Integrity: Imagine a scenario where different parts of an application access and manipulate the same data. Data integrity ensures that the latest, most up-to-date information appears consistently across all forms and screens, preventing discrepancies.
  • Business Rule Conformity: Databases today are more than just storage; they are powerful tools for implementing business logic. Testing ensures that these complex business rules, constraints, triggers, and stored procedures are correctly implemented within the database.

Database testing is about making sure that the database not only stores data but also does so accurately and securely. It's like the invisible assurance that keeps your software running smoothly behind the scenes.

Database Testing with DreamFactory

DreamFactory offers a robust database testing capability. Ensuring that your databases are not only up and running but also performing as expected is crucial for any application. Here's how DreamFactory simplifies the process:

Initialization and Service Creation

DreamFactory kicks off the testing process by initializing variables and creating database services as needed. The configurations specified in servicesToCreate guide this service creation.

Service Connection Test

Before diving into the tests, DreamFactory checks the status of each service in vars.servicesToTest. If a service is active, it proceeds to verify the database service connection, ensuring that your APIs can interact seamlessly with your databases.

Run Tests on Each Service

The real testing begins here. For each active service, DreamFactory runs a series of tests designed to cover various aspects of your database.

Inside testOneService(svc), it tailors its approach based on the type of service:

SQL Services: For SQL services, DreamFactory can either generate sample data or execute application tests.

MongoDB: It conducts tests with different ID configurations.

Other Databases: Application tests are run.

Types of Tests Run

DreamFactory offers a comprehensive suite of tests, including:

  • Sanity Tests: Fundamental checks to ensure the database functions as expected.
  • CRUD Tests: Covering Create, Read, Update, and Delete operations.
  • Pagination Tests: Evaluating pagination-related functionality.
  • Owner ID Tests: Ensuring data is correctly associated with owner IDs.
  • Role Access Tests: Verifying role-based access controls.
  • Rollback Tests: Confirming that transaction rollbacks work as intended.
  • Virtual Field Tests: For SQL services, it tests virtual fields.
  • Related Tests: For SQL services with related data (if config.db.testRelated is true).

Cleanup and Role Management

To maintain a clean testing environment, DreamFactory handles cleanup and role management:

Initialization for CRUD Tests: Deleting existing tables, roles, and users and creating new ones.

User and Role Creation: Creating test users and roles using functions like createUsers() and createRoles().

Role Update: The updateRoles() function is employed to update roles based on different modes and permissions.

Configuration

Customizing tests is a breeze with DreamFactory. You can configure tests for various database types like SQL Server, Oracle, MongoDB, and more using environment variables. The servicesToCreate array provides flexible configuration options for each service.

Utility Functions

DreamFactory employs a range of utility functions to streamline the testing process. These functions are essential for result checking, test execution, and CRUD operations.

Dependencies

To ensure seamless testing across different database types and scenarios, DreamFactory relies on various modules, including scripts.js, related.js, virtual.js, dbCrud.js, config.js, sanity.js, sample.js, alias.js, util.js, crud.js, role.js, auth.js, and api.js.

With DreamFactory's database testing capabilities, you can be confident that your databases are not just operational but also perform flawlessly, helping you deliver robust and reliable APIs.

If you'd like to see the rest of DreamFactory's Scripting capabilities, check out our scripting library here!

Getting Started with DreamFactory

Ready to experience the game-changing benefits of DreamFactory's database testing capabilities? Contact us today to schedule a meeting with our engineers or start your free 14 day trial of DreamFactory now.