Blueprint
  • Blueprint Developer Guide
  • Quick Start
    • Getting Started
    • My First Application
      • Creating Your Application
      • Controllers
      • Routers & Routes
      • Services
      • Resources & Resource Controllers
      • Validating & Sanitizing Input
      • Unit Testing Your Application
      • Policies
  • Developer Guide
    • The Object Model
      • Introduction
      • Classes and Instances
      • Computed Properties
      • Aggregated Properties
      • Mixins
    • Routers and Controllers
      • Introduction
      • Routers
      • Controllers
      • Resources
    • Models
    • The Server
    • Policy Framework
    • Services
    • Messaging Framework
    • Configuration Management
    • Application and Resources
      • Lookup Operation
      • Views
      • Assets
    • Blueprint Modules
    • Blueprint Cluster
      • What is a Blueprint Cluster?
      • Running a Blueprint Cluster
      • Technical Details
    • Testing Framework
    • Command-line Interface (Coming Soon)
Powered by GitBook
On this page
  • Overview
  • Installation
  • Running Test Cases
  • Using an IDE
  • Testing Routes
  • Testing Blueprint Modules
  1. Developer Guide

Testing Framework

Learn to write test cases

PreviousTechnical DetailsNextCommand-line Interface (Coming Soon)

Last updated 3 years ago

Overview

Testing is an integral part of any application. We therefore have a node module and guidelines to testing a Blueprint application. We use the following middleware to facilitate testing:

The remainder of this section will detail how to write test for Blueprint.

Installation

The testing module is automatically installed when you generate a new Blueprint project. But, in case you need to manually install it, or update to the latest version, use the following command.

npm install --save-dev @onehilltech/blueprint-testing 

Do not forget to the --save-dev option when installing the blueprint-testing module.

Running Test Cases

The simplest way to run your test cases is via npm on the command-line.

npm test

This will instruct npm to run all test cases in your tests/unit-tests.

Using an IDE

Testing Routes

tests/unit-tests/app/routers/message-test.js
const { request } = require ('@onehilltech/blueprint-testing');

describe ('app | routers | message', function () {
  it ('should create a message', function () {
    const message = { 
      id: 0, 
      to: 'john.doe@me.com',
      from: 'jane.doe@you.com',
      date: Date.now (), 
      subject: 'Dummy Message',
      content; 'This is a dummy message.'
    };
    
    return request ()
      .post ('/messages')
      .send ({message})
      .expect (200, {message});
  });
});

Testing Blueprint Modules

npm is just one way to run your test cases, but you are not restricted to only using npm. You can use your favorite IDE to run your tests cases, such as . If you choose to run your test cases via an IDE, you must remember that tests/unit-tests/bootstrap.js must load first before running any test cases. This file will load your Blueprint application into memory, and make the application resources available for testing. If you fail to load this file first during your testing exercises, you will get error messages related to the application not being loaded. A common solution to ensure tests/unit-tests/bootstrap.js loads first is to set tests/unit-tests as the starting directory for your unit tests.

You test different routes in Blueprint by sending requests to paths on the Blueprint application under test. For example, the defined the route POST /messages. We can test this route by sending a request a POST request to /messages.

As shown in the example above, we start by importing the request method from . The request method is a helper method that will return a object that initiates a http request against the Blueprint application. The request has the option of returning a Promise that can be returned from the unit testing method to signify asynchronous execution.

chai
chai-datetime
mocha
superagent
supertest
WebStorm
blueprint-testing
supertest request
message router from our previous examples