Getting Started with NoSwag: A Complete Setup Guide

NTnoSwag Team

Getting Started with NoSwag: A Complete Setup Guide

Welcome to the ultimate guide for getting started with NoSwag—the modern, lightweight, and powerful API testing tool designed for developers and QA engineers. Whether you're new to API testing or looking to streamline your workflow, this guide will walk you through everything you need to know to set up NoSwag, configure it for your testing needs, and run your first successful tests.

In this post, you’ll learn:

  • How to install NoSwag
  • Essential configuration steps
  • Running your first API test
  • Best practices for integration

Let’s dive in!

1. What is NoSwag?

NoSwag is a Swagger/OpenAPI-based API testing framework that simplifies the process of testing RESTful APIs. Unlike traditional tools, NoSwag leverages OpenAPI specifications to generate test cases, validate responses, and automate API verification—all while maintaining readability and ease of use.

Key Features

  • OpenAPI Integration: Uses OpenAPI (Swagger) specifications to auto-generate test cases.
  • Lightweight: Minimal setup required, making it ideal for both small and large projects.
  • Flexible: Supports custom assertions, request modifications, and environment variables.
  • Automation-Friendly: Easily integrates with CI/CD pipelines.

2. Installation Guide

Prerequisites

Before installing NoSwag, ensure you have:

  • Node.js (v14 or later)
  • npm or yarn
  • A valid OpenAPI/Swagger specification (JSON or YAML)

Step-by-Step Installation

  1. Install NoSwag via npm

    npm install -g noswag
    

    (Or use yarn global add noswag if you prefer Yarn.)

  2. Verify Installation Run the following command to check if NoSwag is installed correctly:

    noswag --version
    
  3. Initialize a NoSwag Project Navigate to your project directory and run:

    noswag init
    

    This will generate a default noswag.config.js file.


3. Configuration Basics

The noswag.config.js file is where you define test settings, API endpoints, and custom behaviors.

Sample Configuration File

module.exports = {
  api: {
    baseUrl: "https://api.example.com/v1",
    openApiSpec: "./swagger.json" // Path to your OpenAPI file
  },
  tests: {
    validateStatusCode: true, // Automatically check for 2xx responses
    timeout: 5000, // Test timeout in milliseconds
  },
  reporters: ["json", "cli"], // Output formats
  environment: {
    authToken: process.env.API_TOKEN, // Use environment variables
  }
};

Key Configuration Options

OptionDescription
baseUrlThe root URL for API requests.
openApiSpecPath to the OpenAPI/Swagger file.
validateStatusCodeEnables automatic status code validation.
timeoutSets a global timeout for all tests.
reportersDefines test output formats (e.g., cli, json, html).
environmentStores dynamic values (e.g., API keys).

4. Running Your First Test

Basic Test Example

Let’s run a simple test against a /users endpoint.

  1. Define a Test Case Create a users.test.js file:

    const { test, expect } = require('@noswag/core');
    
    test('GET /users should return a list of users', async () => {
      const response = await api.users.get(); // Auto-generated from OpenAPI
      expect(response.status).toBe(200);
      expect(response.body).toHaveLength(10); // Expect 10 users
    });
    
  2. Run the Test Execute the test using:

    noswag test users.test.js
    

Advanced Testing with Assertions

NoSwag supports custom assertions and conditional checks:

test('POST /users should create a new user', async () => {
  const newUser = { name: "John Doe", email: "john@example.com" };
  const response = await api.users.post(newUser);

  expect(response.status).toBe(201);
  expect(response.body).toMatchObject({
    id: expect.any(String), // Check for a valid ID
    name: "John Doe",
  });
});

5. Best Practices for API Testing with NoSwag

1. Use Environment Variables for Sensitive Data

Instead of hardcoding API keys, use environment variables:

API_TOKEN=your_token noswag test

2. Organize Tests by Endpoints

Group tests logically (e.g., users.test.js, products.test.js).

3. Leverage OpenAPI for Test Generation

NoSwag automatically generates test stubs from your OpenAPI file, reducing manual work.

4. Integrate with CI/CD

Run NoSwag tests in your pipeline:



# GitHub Actions Example


- name: Run NoSwag Tests
  run: noswag test

5. Use Mocking for Unstable Dependencies

If certain endpoints are unreliable, mock them:

test('GET /orders with mock', async () => {
  api.mock('/orders', { status: 200, body: [] });
  const response = await api.orders.get();
  expect(response.body).toEqual([]);
});

6. Conclusion

NoSwag simplifies API testing by leveraging OpenAPI specifications, reducing boilerplate, and providing a clean, modern testing experience. By following this guide, you now have a solid foundation to: ✅ Install and configure NoSwag ✅ Write and run API tests ✅ Integrate testing into your workflow

Ready to take your API testing to the next level? Start experimenting with NoSwag today and share your experiences in the comments! 🚀

Happy Testing!

Related Articles

API Change Management: Leading Organizational Transformation

NTnoSwag Team

Guide to managing organizational change around API initiatives, including change management frameworks, communication strategies, and adoption metrics.

CEO's Quality Investment Strategy: Building a Quality-First Culture

NTnoSwag Team

Strategic approach for CEOs to invest in quality initiatives and build a quality-first organizational culture, including cultural transformation, investment prioritization, and organizational excellence.

API Testing Side Projects: Building Experience Outside Your Day Job

NTnoSwag Team

Guide to API testing side projects and personal development, including project ideas, skill building, and portfolio enhancement strategies.

Read more

API Change Management: Leading Organizational Transformation

Guide to managing organizational change around API initiatives, including change management frameworks, communication strategies, and adoption metrics.

CEO's Quality Investment Strategy: Building a Quality-First Culture

Strategic approach for CEOs to invest in quality initiatives and build a quality-first organizational culture, including cultural transformation, investment prioritization, and organizational excellence.

API Testing Side Projects: Building Experience Outside Your Day Job

Guide to API testing side projects and personal development, including project ideas, skill building, and portfolio enhancement strategies.

API Testing Interview Preparation: Landing Your First Job

Comprehensive guide to API testing interview preparation, including common questions, technical assessments, and interview success strategies.