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.
javascript-testing/
├── src
│ ├── controllers
│ ├── database
│ ├── models
│ ├── routes
│ ├── server
│ └── views
├── tests
│ ├── e2e
│ │ └── backend
│ │ └── frontend
│ ├── integration
│ ├── performance
│ ├── security
│ └── unit
It was used on GitHub Actions to build the CI\CD pipeline.
┌─────Build─────┐┌──────────────────────────────────Test───────────────────────────────────┐
═══⦿══════════⦿══════════⦿══════════⦿══════════⦿══════════⦿═══════════⦿═══════════⦿═══
Pull Build Unit Integration Backend Frontend Performance Security
- Backend: Javascript, Express.js, Mongoose and MongoDB.
- Frontend: HTML, CSS and EJS.
- Unit Testing: Jest, Proxyquire and Sinon.
- Integration Testing: Jest, Supertest and MongoDB In-Memory Server.
- API Testing: Jest and Axios.
- GUI Testing: Jest, Puppeteer and Faker.js.
- Performance Testing: Artillery.
- Security Testing.
-
Create a .env file in the root directory of your project.
PORT=3000 MONGO_URI=mongodb://localhost:27017 MONGO_NAME=cards
-
Start MongoDB Container
$ docker-compose up
-
Install Dependencies
$ npm install
-
Run the Application
$ npm start
-
Run Tests
$ npm test
-
Run Test Coverage
$ npm run coverage
This project uses the design patterns from Airbnb JavaScript Style Guide.
- Fast
- Independent
- Repeatable
- Self-Validating
- Timely
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.
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.
- 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.
- 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.
- 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.
- 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.