How to Achieve Automated Testing Within Sprint?

How to Achieve Automated Testing Within Sprint?

posted Originally published at medium.com 4 min read

How to Achieve Automated Testing Within Sprint?

In the debate over whether automated testing should wait until development is completed, one compelling argument for early testing is the use of dummy test cases. Dummy test cases are simple, placeholder tests that can be implemented early in the development process to ensure that the testing framework is in place and functioning correctly. This article explores how to implement dummy test cases and how they can encourage a culture of early automated testing.

What are Dummy Test Cases?

Dummy test cases are basic, often minimalistic tests that serve as placeholders in the early stages of development. They are not meant to thoroughly test the application but to ensure that the testing infrastructure is set up correctly and to provide a foundation for more comprehensive tests later on.

Let's Understand the concept of Dummy Tests by real world example

Dummy Tests for a Login Feature

Let's create some dummy tests for a login feature using Playwright (you can write for Selenium, Cypress, webdriver.io in similar way). These tests will serve as placeholders and ensure that the testing framework is set up correctly.
Setting Up Playwright -

npm install - save-dev playwright

Creating Dummy Tests

To keep the dummy test data in a separate file and segregate the test and data, you can follow these steps:

  1. Create a Separate File for Dummy Test Data
  2. Move Dummy Test Data to the New File
  3. Import and Use Dummy Test Data in Your Test File

Step 1: Create and Move Dummy Test Data to the New File

Create a new file named dummyTestData.ts in the tests folder. Move the dummy test data to the new file dummyTestData.ts:

// tests/dummyTestData.ts

export const loginTestData = {
    validUser: {
        username: 'validUser',
        password: 'validPass',
    },
    invalidUser: {
        username: 'invalidUser',
        password: 'invalidPass',
    },
    // TBA = To Be Added
    selectors: {
        loginForm: 'TBA',
        loginButton: 'TBA',
        usernameInput: 'TBA',
        passwordInput: 'TBA',
        errorMessage: 'TBA',
        welcomeMessage: 'TBA',
    },
};

Step 2: Import and Use Dummy Test Data in Your Test File

Import the dummy test data into your test file and use it in your tests. For example, in login.test.ts:

// tests/login.test.ts

import { test, expect } from '@playwright/test';
import { loginTestData } from './dummyTestData';

test.describe('Login Feature', () => {
    test('Dummy Test Case 1: Page should have a login form', async ({ page }) => {
        await page.goto('https://example.com/login');
        const loginForm = await page.$(loginTestData.selectors.loginForm);
        expect(loginForm).not.toBeNull();
    });

    test('Dummy Test Case 2: Login button should be disabled initially', async ({ page }) => {
        await page.goto('https://example.com/login');
        const loginButton = await page.$(loginTestData.selectors.loginButton);
        const isDisabled = await loginButton?.isDisabled();
        expect(isDisabled).toBe(true);
    });

    test('Dummy Test Case 3: Should display error message for invalid credentials', async ({ page }) => {
        await page.goto('https://example.com/login');
        await page.fill(loginTestData.selectors.usernameInput, loginTestData.invalidUser.username);
        await page.fill(loginTestData.selectors.passwordInput, loginTestData.invalidUser.password);
        await page.click(loginTestData.selectors.loginButton);
        const errorMessage = await page.$(loginTestData.selectors.errorMessage);
        expect(errorMessage).not.toBeNull();
    });

    // Add real tests here as development progresses
    test('Real Test Case: Successful login', async ({ page }) => {
        await page.goto('https://example.com/login');
        await page.fill(loginTestData.selectors.usernameInput, loginTestData.validUser.username);
        await page.fill(loginTestData.selectors.passwordInput, loginTestData.validUser.password);
        await page.click(loginTestData.selectors.loginButton);
        await page.waitForNavigation();
        const welcomeMessage = await page.$(loginTestData.selectors.welcomeMessage);
        expect(welcomeMessage).not.toBeNull();
    });
});

Explanation

dummyTestData.ts: This file contains the dummy test data. The loginTestData object holds the test data for the login feature, including valid and invalid user credentials and selectors.

login.test.ts: This file imports the loginTestData object and uses it in the dummy test cases. This keeps the test data separate from the test logic, making the code more organized and maintainable.

Running the Tests

Run the tests using the Playwright Test runner:

npx playwright test

Benefits of Dummy Test Cases

Early Detection of Issues: By implementing dummy test cases early, teams can identify and resolve issues with the testing framework, dependencies, and configurations before they become critical problems.

Continuous Feedback: Dummy test cases provide continuous feedback to developers, ensuring that the basic functionality of the application is being tested from the outset.

Encourages a Testing Culture: Implementing dummy test cases early in the development process encourages a culture of testing within the team. It sets the expectation that testing is an integral part of development, not an afterthought.

Reduces Technical Debt: Early testing helps to identify and fix issues before they accumulate, reducing technical debt and making the codebase more maintainable.
Facilitates Test-Driven Development (TDD): Encourage TDD approach where tests are written before the actual code.

Cost-Effective: Implementing dummy tests requires minimal effort and resources, making it a cost-effective way to improve the testing process.
Improves Test Coverage: Dummy tests provide a baseline level of test coverage, ensuring that at least the basic functionality is being tested.

Conclusion

This approach encourages early automated testing, providing continuous feedback and fostering a culture of quality within the development team. By keeping the dummy test data in a separate file, you can maintain a clean and organized codebase. This approach allows you to easily manage and update test data while keeping your test files focused on the test logic. This practice encourages early automated testing and helps in maintaining a high level of code quality throughout the development lifecycle.


If you enjoyed this story, please like and share to help others find it! Feel free to leave a comment below.

If you read this far, tweet to the author to show them you care. Tweet a Thanks
Great article! I really like how you emphasized the importance of dummy test cases in fostering a testing culture early in the development process. Separating test data into a dedicated file is a clean and scalable approach, making tests more maintainable. Also, the Playwright example is well-explained and practical. This method can definitely help teams reduce technical debt and encourage TDD. Thanks for sharing!
Thanks Adewumi, Glad!! you liked it, please do share with others.

More Posts

How to use Builder design Pattern for test data generation in automation testing

Faisal khatri - Oct 14, 2024

Testing in Python: Writing Test Cases with unittest

Abdul Daim - Apr 8, 2024

Unit Testing in Python

Abdul Daim - Apr 4, 2024

Meet the .csv datasets and understand how they works on creating expert system Artificial Intelligence models

Elmer Urbina - Oct 19, 2024

Exploring Ansible Adhoc Commands For Beginners

Ahamed Kabeer Choudary - Feb 15
chevron_left