Testing Strategy: How We Ship With Confidence

A robust software testing strategy achieves high deployment confidence by balancing unit tests for pure logic, integration tests for system interactions, and E2E tests for critical user journeys. At Kraftwire, we prioritize tests that mirror real-world behavior, ensuring that our six-week MVP delivery remains stable even under rapid iteration. Shipping with confidence means knowing that a passing test suite guarantees a functional user experience, not just a green light on an isolated function.
The Confidence Gradient
Every test in a modern pipeline answers a specific question: "If this passes, what can I safely deploy?" Confidence is not a binary state but a gradient. Unit tests provide high confidence in low-level logic but zero confidence in how that logic interacts with a database. E2E tests provide high confidence in the entire stack but are slow and prone to "flakiness" if not managed correctly.
The goal of a professional custom software project is not 100% code coverage. High coverage can be a vanity metric if it only tests trivial getters and setters. Instead, we aim for the minimum amount of testing that provides the maximum amount of deployment certainty. This is especially critical when building for regulated industries or complex SaaS platforms, where a single regression can lead to data integrity issues.
The Testing Trophy vs. The Pyramid
The traditional testing pyramid suggests a massive base of unit tests, a middle layer of integration tests, and a tiny tip of E2E tests. While this was standard for decades, modern web development often benefits from the "Testing Trophy" model, popularized by Kent C. Dodds.
- Static Analysis: Catching typos and type errors before the code even runs (TypeScript/ESLint).
- Unit Tests: Verifying isolated business logic and pure functions.
- Integration Tests: The "sweet spot" where most of your effort should go, verifying how components work together.
- E2E Tests: High-level verification of the most critical paths using a real browser.
For applications with heavy UI and complex business logic, we often find that integration tests provide the best return on investment. They verify that the API, the database, and the frontend components work together without the overhead of a full browser environment for every single check. This approach aligns with our agile approach, allowing us to maintain speed without sacrificing the stability of the final product.
Unit Tests: Pure Logic Only
Unit tests are most effective when applied to "pure functions" · functions that take an input, return an output, and have no side effects. If a function reaches out to a database or an external API, it is no longer a candidate for a simple unit test; it belongs in the integration layer.
We typically use Vitest for these scenarios. Vitest is a Vite-native testing framework that provides a compatible API with Jest while offering faster execution through Vite's transformation pipeline. This speed is essential for the "red-green-refactor" cycle during MVP development.
// Example: Pure logic for a fintech application
// Verifying discount logic without touching a database
function calculateDiscount(items: Item[], coupon: Coupon): number {
if (!coupon.isValid()) return 0;
const eligibleItems = items.filter(item =>
coupon.categories.includes(item.category)
);
const subtotal = eligibleItems.reduce((sum, item) => sum + item.price, 0);
return coupon.type === 'percentage'
? subtotal * (coupon.value / 100)
: Math.min(coupon.value, subtotal);
}
// Vitest Test Suite
describe('calculateDiscount', () => {
it('returns 0 for invalid coupon', () => {
const items = [{ category: 'electronics', price: 100 }];
const coupon = { isValid: () => false, value: 20, type: 'percentage' };
expect(calculateDiscount(items, coupon)).toBe(0);
});
it('applies percentage discount to eligible items only', () => {
const items = [
{ category: 'electronics', price: 100 },
{ category: 'clothing', price: 50 }
];
const coupon = {
isValid: () => true,
categories: ['electronics'],
value: 10,
type: 'percentage'
};
expect(calculateDiscount(items, coupon)).toBe(10); // 10% of $100
});
});
Integration Tests: Verifying the "Glue"
Integration tests are the backbone of a reliable API development strategy. They ensure that when a user hits an endpoint, the controller talks to the service, the service talks to the database, and the correct response is returned.
Instead of mocking the database, we prefer using a "test database" that is wiped between runs. This catches issues like constraint violations, incorrect SQL queries, or database design flaws that mocks would miss. By using tools like Prisma or Drizzle ORM alongside a local Dockerized PostgreSQL instance, we can simulate production environments with high fidelity.
// Testing an API endpoint with a real PostgreSQL instance
describe('POST /api/orders', () => {
beforeEach(async () => {
// Clear the database to ensure test isolation
await db.from('orders').delete().neq('id', '00000000-0000-0000-0000-000000000000');
});
it('creates order and updates inventory', async () => {
// 1. Setup: Create a real product in the DB
const { data: product } = await db.from('products').insert({
name: 'Test Product',
price: 99.99,
inventory: 10
}).select().single();
// 2. Act: Call the API
const response = await request(app)
.post('/api/orders')
.send({
items: [{ productId: product.id, quantity: 2 }]
})
.expect(201);
// 3. Assert: Check response and side effects
expect(response.body.data.total).toBe(199.98);
const { data: updatedProduct } = await db
.from('products')
.select('inventory')
.eq('id', product.id)
.single();
expect(updatedProduct.inventory).toBe(8);
});
});
E2E Tests: Critical User Journeys
End-to-End (E2E) tests simulate a real user interacting with the application in a browser. At Kraftwire, we use Playwright for this. Playwright allows testing across Chromium, WebKit, and Firefox with a single API, supporting mobile emulation and headless modes. This is vital for ensuring that our KW Native conversions maintain UI integrity across different viewports.
Because E2E tests are slower and more resource-intensive, we reserve them for "Happy Paths" that are critical to the business:
- Revenue Paths: Checkout, subscription upgrades, and payment processing.
- Authentication: Login, signup, and password recovery (essential for security compliance).
- Core Value Prop: For a social network like Ginza, this would be posting a status or sending a message.
// Playwright E2E test for a checkout flow
test('complete checkout as new user', async ({ page }) => {
await page.goto('/products/test-product');
await page.click('button:has-text("Add to Cart")');
await page.click('[data-testid="cart-icon"]');
await expect(page.locator('[data-testid="cart-count"]')).toHaveText('1');
await page.click('button:has-text("Checkout")');
// Fill shipping info
await page.fill('[name="email"]', 'test@example.com');
await page.fill('[name="address"]', '123 Test St');
await page.fill('[name="city"]', 'Test City');
await page.fill('[name="zip"]', '12345');
await page.click('button:has-text("Place Order")');
// Final verification
await expect(page.locator('h1')).toContainText('Order Confirmed');
await expect(page.locator('[data-testid="order-number"]')).toBeVisible();
});
The Test Data Problem: Factories vs. Fixtures
One of the biggest hurdles in testing is maintaining a consistent state. Hard-coded fixtures often become stale as the database schema evolves. We recommend the Factory Pattern to generate dynamic, valid test data on the fly. This ensures that tests don't break simply because a new required field was added to the user table.
// Factory pattern for scalable test data
const createTestUser = async (overrides = {}) => {
const defaults = {
email: `test-${Date.now()}@example.com`,
name: 'Test User',
plan: 'free'
};
const userData = { ...defaults, ...overrides };
const { data } = await db.from('users').insert(userData).select().single();
return data;
};
// Usage in a history test
it('shows order history', async () => {
const user = await createTestUser({ plan: 'premium' });
await createTestOrder(user.id, { status: 'completed' });
const response = await request(app)
.get(`/api/users/${user.id}/orders`)
.expect(200);
expect(response.body.data).toHaveLength(1);
});
Internal Tools and Open Source Alternatives
When building internal tools, engineering teams often look for alternatives to platforms like Retool, especially when self-hosting and cost-efficiency are priorities. ToolJet is a notable open-source Retool alternative that is highly suitable for engineering teams. It allows for building internal tools with a drag-and-drop interface while offering self-hosting options and, crucially, no per-user licensing fees in its basic self-hosted version. This makes it an excellent choice for startups looking to scale their internal operations without the overhead of proprietary SaaS pricing.
For teams that have outgrown standard website builders and need to integrate with complex systems like Learning Management Systems (LMS), custom software is often the only way to ensure deep integration. While builders like Webflow or WordPress have LMS plugins, they often lack the granular testing capabilities required for high-stakes educational platforms. A custom web application allows for rigorous integration testing between the student portal, the content delivery network, and the assessment engine, ensuring a seamless learning experience.
CI/CD Integration: The Gatekeeper
A testing strategy is only as good as its enforcement. Tests must run automatically on every pull request. We utilize GitHub Actions to orchestrate this. GitHub Actions allows running multi-container setups using service containers, which is ideal for hosting databases like PostgreSQL during test runs.
A typical workflow includes:
- Linting & Type Checking: Immediate feedback on syntax and types via ESLint and TypeScript.
- Unit & Integration Tests: Running in parallel to save time and provide fast feedback loops.
- E2E Tests: Running against a staged version of the app to verify the full deployment stack.
- Deployment: Only triggered if all previous steps pass, ensuring zero breaches through accidental regressions.
# GitHub Actions snippet for automated testing
name: Test Suite
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: test
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: npm ci
- name: Run Unit Tests
run: npm run test:unit
- name: Run Integration Tests
run: npm run test:integration
- name: Run Playwright E2E
run: npx playwright test
Conclusion: Shipping Without Anxiety
Testing is not about finding every single bug; it is about creating a safety net that allows your team to move fast. By focusing on integration tests and critical E2E paths, you ensure that your application remains functional for the end-user while maintaining a high velocity of development.
Whether you are building a fintech platform or a social network, a structured testing strategy is the difference between a stressful release day and a confident deployment. At Kraftwire, we bake these practices into every project to ensure that our six-week delivery target never compromises on quality. For more on how we maintain high standards during rapid development, explore our agile approach or learn about our security compliance protocols. By investing in a robust testing suite today, you are protecting the future scalability and reliability of your software.
FAQ
What is the difference between unit and integration testing? Unit tests focus on individual functions or components in isolation, usually mocking external dependencies like databases. Integration tests verify that different parts of the system, such as the API and the database, work together correctly. While unit tests are faster, integration tests provide higher confidence in the overall system behavior by testing the "glue" between modules.
When should I use E2E tests instead of unit tests? End-to-End (E2E) tests simulate real user interactions in a browser environment. You should prioritize E2E tests for critical business paths, such as user authentication, payment processing, and core feature workflows. Because they are slower and more expensive to maintain, avoid using them for minor UI details or simple logic that unit tests can cover.
Why is Playwright recommended for E2E testing? Playwright is a modern testing framework that allows you to automate interactions across Chromium, Firefox, and WebKit with a single API. It is highly valued for its speed, reliability, and built-in features like auto-waiting and trace viewing. These features help reduce "flaky" tests that often plague older E2E testing tools, making it ideal for professional CI/CD pipelines.
What is the Testing Trophy and why does it matter? The Testing Trophy is a model that prioritizes integration tests over unit tests. It suggests that integration tests provide the best balance between execution speed and deployment confidence. By focusing on how components interact, developers can catch more significant bugs than by testing isolated logic alone, leading to more stable production environments.
How do I handle database state and test data? Managing test data is best handled through the Factory Pattern, where dynamic, valid data is generated for each test run. This avoids the "stale data" problem associated with static fixtures. Additionally, using a dedicated test database that is cleared between runs ensures isolation and prevents side effects from one test affecting the results of another.
Is ToolJet a good open-source alternative to Retool? Yes, ToolJet is highly suitable for engineering teams seeking an open-source Retool alternative. It supports self-hosting on your own infrastructure, which is ideal for security-conscious organizations. Unlike many proprietary platforms, ToolJet does not charge per-user licensing fees for its basic self-hosted version, making it a cost-effective solution for building internal tools at scale.
FAQ
What is the difference between unit and integration testing?
Unit tests focus on individual functions or components in isolation, usually mocking external dependencies like databases. Integration tests verify that different parts of the system, such as the API and the database, work together correctly. While unit tests are faster, integration tests provide higher confidence in the overall system behavior by testing the "glue" between modules.
When should I use E2E tests instead of unit tests?
End-to-End (E2E) tests simulate real user interactions in a browser environment. You should prioritize E2E tests for critical business paths, such as user authentication, payment processing, and core feature workflows. Because they are slower and more expensive to maintain, avoid using them for minor UI details or simple logic that unit tests can cover.
Why is Playwright recommended for E2E testing?
Playwright is a modern testing framework that allows you to automate interactions across Chromium, Firefox, and WebKit with a single API. It is highly valued for its speed, reliability, and built-in features like auto-waiting and trace viewing. These features help reduce "flaky" tests that often plague older E2E testing tools, making it ideal for professional CI/CD pipelines.
What is the Testing Trophy and why does it matter?
The Testing Trophy is a model that prioritizes integration tests over unit tests. It suggests that integration tests provide the best balance between execution speed and deployment confidence. By focusing on how components interact, developers can catch more significant bugs than by testing isolated logic alone, leading to more stable production environments.
How do I handle database state and test data?
Managing test data is best handled through the Factory Pattern, where dynamic, valid data is generated for each test run. This avoids the "stale data" problem associated with static fixtures. Additionally, using a dedicated test database that is cleared between runs ensures isolation and prevents side effects from one test affecting the results of another.
Is ToolJet a good open-source alternative to Retool?
Yes, ToolJet is highly suitable for engineering teams seeking an open-source Retool alternative. It supports self-hosting on your own infrastructure, which is ideal for security-conscious organizations. Unlike many proprietary platforms, ToolJet does not charge per-user licensing fees for its basic self-hosted version, making it a cost-effective solution for building internal tools at scale.