TypeScript guides
Mastery Toolkit
Testing
10 min
automated testing is a cornerstone to successful software development tests are not just to ensure that your application is working as intended, they are also to ensure that existing features aren't broken by any newly introduced features or code , aka regression bugs the latter tends to hold more value, as it makes the software sturdy and less prone to these types of bugs during active development of a project regression bugs will quickly stall the development of a project at a certain level of complexity, effectively preventing progress smtp testing https //mailtrap io/inboxes https //mailtrap io/inboxes add credentials in env local smtp host=smtp mailtrap io smtp port=2525 smtp user=\<mailtrap user> smtp pass=\<mailtrap password> unit tests unit tests focus on testing small pieces of code, usually just a single function, which only does one specific thing const add2 = x => x + 2 it('should add 2 to a given number', () => { strictequal(add2(1), 3) }) integration tests integration tests focus on testing bundles of code units a composition of functions, for example const addtwo = x => x + 2 const multthree = x => x 3 const halve = x => x / 2 const algorithm = x => { x = addtwo(x) x = multthree(x) x = halve(x) return x } it('should apply the entire algorithm correctly', () => { strictequal(algorithm(4), 9) }) unit vs integration tests ( source https //www geeksforgeeks org/difference between unit testing and integration testing/ ) unit testing integration testing in unit testing each module of the software is tested separately in integration testing all modules of the the software are tested combined in unit testing the tester knows the internal design of the software in integration testing the tester doesn't know the internal design of the software unit testing is performed first of all testing processes integration testing is performed after unit testing, and before system/end to end tests unit testing is a white box testing integration testing is a black box testing unit testing is performed by the developer integration testing is performed by the tester detection of defects in unit testing is easy detection of defects in integration testing is difficult it tests parts of the project without waiting for others to be completed it tests only after the completion of all parts unit testing is less costly integration testing is more costly system tests system tests can be thought of much like unit tests, but on a grand level these tests focus on ensuring that one particular system/module is functioning as expected from the outside using maps as an example, one may test that each one of these systems are working correctly the map api download the mesh construction procedural mesh loading end to end tests end to end tests can be thought of much like integration tests, but also on a grand level these tests focus on flows between systems using the previous maps example, an end to end test would ensure that the entire flow of map api download, constructing meshes, and procedural loading together in one continuous flow (one whole end to end test for this entire flow) is working correctly system vs end to end tests ( source https //www geeksforgeeks org/difference between system testing and end to end testing/ ) system testing end to end testing in system testing, whole software or application is tested at a time in end to end testing, behavioral flow of the software is tested system testing only tests the specific software system it tests the software system and the connected systems both the functionality of the software is tested flow from end to end is tested it validates the software system as per standards and specifications it validated all the interfaces of the software knowledge of interconnected systems is not required knowledge about interconnected systems is required it is carried out once integration testing is performed it is performed after the system testing it is performed both manually and automated it is generally performed manually it is the super set of end to end testing it is considered as subset of the system testing white box vs black box testing in simple terms, white box testing happens when the tester knows exactly how the internals of the tested code are working, and knows exactly what to test and what to expect unit testing is white box testing black box testing, on the other hand, happens when the tester does not know anything about how the internals of the code are working, and only knows what the input and expected output should be integration, system, and end to end testing are all black box testing the testing pyramid a typical suggestion is to aim for a 70/20/10 split between these different types of tests although more coverage is never a bad thing, the aim should be to bolster the tests with respect to the following pyramid distribution 70% unit tests 20% integration tests 10% end to end tests /```\\ / e2e \\ / \\ / \\ /integration\\ / \\ / \\ / unit \\ / \\