Closed huumanoid closed 8 years ago
Thanks @HuuMaNoID for your amazing work! I will test this and merge.
Regarding the "Should not receive a message" test-case question, I can't think on a better way of doing that but since it's a local server what we are testing, the time should not vary much.
@HuuMaNoID Merged! I made a few changes to your original PR, please, can you check if master
branch it's working as supposed? Thanks.
Introduction
Often our code break down after some changes. The main cause of bugs is stupid mistakes, which i have made a lot while working on this project. I'm tired of being scary and suggest to add tests. I've tried to implement some integration tests.
Notice
This document is incomplete, and It take some time to complete it. Also, maybe i need to change something in my solution, and maybe i need to explain something to you.
How to use
coffee src/test/db-init.coffee
for setting up database for tests.npm test
.Implementation
Tools
Files structure
test
foldersrc/test
Tests structure
Tests are logically divided into multiple files. Currently, there are four files, which tests different functionality
Before performing tests, database structure should be set up. db-init.coffee performs database initialization for tests purposes. It creates users and chats for tests. There are some reserved userids and chatids: users from 50 to 100 chats from 100 to 200.
Typical flow of test in every file:
Problems
Kind of tests
The implemented tests are integration tests. Unit tests can be more reliable, but they require suitable program design, so i don't think we are ready for them. Moreover, may be integration tests are enough?
"Should not receive a message" test-case
Often we need to cut illegal messages: for example, if non-admin user tries to ban someone, no one should be banned, so we want to test if victim receives 'banned' message or not. According to using test type, the easiest way to test this case is to use delay: Set up: User Mallory and user Bob connected to chat 50. They are both guests.
Results
This solution already helped me to fix one bug just today. May be it helped to fix some bugs in past, but i don't remember it.