Skip to content

White-box, black-box and non-functional test demonstration in an Express.js-based application with MVC pattern (Model-View-Controller). Tools: Jest, Supertest, Axios, Puppeteer, Sinon and MongoDB.

Notifications You must be signed in to change notification settings

leoduprates/javascript-testing

Repository files navigation

Javascript NodeJS Express.js MongoDB Jest LinkedIn

CI coverage

Javascript Testing

Project developed using the Dev-Test-Ops approach, consisting of application development, test and delivery.

This strategy gives the opportunity to design the application to remain testable across all layers including the CI\CD.

Application, test and infrastructure as code are in the same domain. Developer and QA have the same role and responsibilities as an engineer with full access to white box, black box and non-functional testing.

Project Architecture

javascript-testing/
├── src
│   ├── controllers
│   ├── database
│   ├── models
│   ├── routes
│   ├── server
│   └── views
├── tests
│   ├── e2e
│   │   └── backend
│   │   └── frontend
│   ├── integration
│   ├── performance
│   ├── security
│   └── unit

Continuous Integration and Delivery

It was used on GitHub Actions to build the CI\CD pipeline.

┌─────Build─────┐┌──────────────────────────────────Test───────────────────────────────────┐

═══⦿══════════⦿══════════⦿══════════⦿══════════⦿══════════⦿═══════════⦿═══════════⦿═══ 
  Pull       Build       Unit    Integration   Backend    Frontend   Performance   Security

Built With

Getting Started

  1. Create a .env file in the root directory of your project.

    PORT=3000
    MONGO_URI=mongodb://localhost:27017
    MONGO_NAME=cards
    
  2. Start MongoDB Container

    $ docker-compose up
  3. Install Dependencies

    $ npm install
  4. Run the Application

    $ npm start
  5. Run Tests

    $ npm test
  6. Run Test Coverage

    $ npm run coverage

Best Practices

Design Patterns

This project uses the design patterns from Airbnb JavaScript Style Guide.

F.I.R.S.T Principles

  • Fast
  • Independent
  • Repeatable
  • Self-Validating
  • Timely

Arrange, Act & Assert (AAA)

The tests were structured with 3 well-separated sections, Arrange, Act and Assert (AAA).

  • Arrange: Setup all dependencies of the test scenario. This can include instantiating constructors, database records, stub or mock objects, and any other dependencies.
  • Act: Execute the test.
  • Assert: Ensure the result was as expected.

Behavior-Driven Development (BDD)

Using declarative ways of writing code allows learning to be fast and cohesive. This helps to organize the tests and more easily understand possible issues. Because of this, Jest was chosen to provide among other functionality the structures for the BDD.

Doubles

  • Mocks: Replace a real object by providing autonomous responses to method calls.
  • Stubs: Modify a function and delegate control over its behavior.
  • Spies: Spy can modify the behaviour of the original object, manipulating method call parameters and/or results.

Test

White-Box Testing

  • Unit Testing: It's a way to test the smallest piece of code that can be logically isolated on a system.
  • Integration Testing: It is a form of testing in which software modules are logically integrated and tested as a group.

Black-Box Testing

  • Backend Testing: Tests the server-side and database of an application.
  • Frontend Testing: Tests the client side of the application, verifying GUI functionality and usability.

Non-functional Testing

  • Performance Testing: Test application performance under normal and high-demand conditions by evaluating stability, scalability, reliability, speed, and usage of infrastructure resources.
  • Security Testing: Test the application by looking for weaknesses and security vulnerabilities.

Links

About

White-box, black-box and non-functional test demonstration in an Express.js-based application with MVC pattern (Model-View-Controller). Tools: Jest, Supertest, Axios, Puppeteer, Sinon and MongoDB.

Topics

Resources

Stars

Watchers

Forks