Posts

Showing posts with the label Test Driven Development

[Testing] Getting Started with Software Testing

Software Testing: is an investigation conducted to provide stakeholders with information about the quality  of the software product or service under test (SUT). Can provide an objective, independent view of the software to allow business to appreciate and understand the risk of software implementation. aims to execute a program or application with the intent to find software bugs. is an iterative process as when one bug is fixed, it can illuminate other, deeper bugs, or can even create new ones. In general, they aim to make sure component of system under test: meets requirements that guided its design and development responds correctly to all kinds of inputs performs its functions within an acceptable time is sufficiently usable can be installed and run in its indented environment achieves the general result its stakeholders desire. Defects and Failures Not all software defects are caused by coding errors. One common source of expensive defects is requireme...

[Unit Testing] Unit Test as a Bug Report

Image
When a test fails, that test failure report should be your best place to find what went wrong and give you clues to tracking the root cause . What's in a good Test Failure Bug Report? What are you testing? What should it do? What was the output (actual behavior)? What was the expected output (expected behavior)? (Example of good failure report) In the screenshot above, it's clear that we are testing 'compose()'. What is should do is to 'return a function'. It also shows expected, and actual, addition to the operator for our assert method. Resources: https://medium.com/javascript-scene/what-every-unit-test-needs-f6cd34d9836d

[Unit Testing] Best Practices of Unit Testing

1. Arrange, Act, Assert Think of each test as a hypothesis, and your test run as an experiment. Arrange; instantiate an object. Act; invoke a method and capture the reuslt. Assert; assert the hypothesis to prove it correct (or wrong). (You should 'tear down' after these 3 As) 2. One Assert per Test Method Don't have to be strictly followed, but a general guideline. Beginners have a tendency to try to test everything in one test method. But it'll be hard to pin down all the errors at once. 3. Avoid Test Interdependence Each test should handle its own setup and tear down. The test runner you use might execute several tests in parallel, and therefore, you don't want one test to depend on another test's state. While your test runner might execute your test in a particular order today, it might execute it in a different order tomorrow. To avoid confusion, just avoid test interdependence. 4. Keep it short, sweet and visible Resist the impulse t...

[Unit Testing] Getting Started with Unit Testing

Image
Unit Testing: Is a software development process in which the smallest  testable parts of an application are individually and independently tested . Simply verifies that individual units of code (mostly functions) work as expected. Is a component of test-driven development (TDD). Usually performed by the developer. Performed using White Box Testing method. Is meant to give the developer more confidence  and trust  in the code. Encourages modularity - write programs that do one thing, and do it well! (Single Responsibility Principal) Involves faking dependencies and methods in order to isolate the scope of the System Under Test (SUT) Simple Example The most simple example is testing the result of a method is within our expectation. For example, we we have a combineNumbers method below: To test this, we simply compare the result of this method with our expected  result. When you run the tests, you will be informed that these tests have passed....

[Unit Testing] Test Doubles (Stubs, Mocks....etc)

Image
In unit testing, isolation is key. The goal of unit testing is to test individual components, and not an entire system . The class/object/function you are testing is System Under Test (SUT) , and the other components of the system are Collaborators or Dependencies. Test Double  is a generic term for any kind of 'pretend' object used in place of a real object for testing purposes.  There are several types of Testing Doubles. We will start with: Fake Stub Mock Command Queries Mocks vs Stubs And then: Dummy Spies Spies vs Mocks I) Basic Testing Doubles a) Fake Fake are objects that have working implementations, but not same as production one. Usually they take some shortcut and have simplified version of production code. Note that Fake is a generic term - that can point to anything; usually mock and stubs. An example of this is an in-memory implementation of a database. This fake implementation will not access the actual database, but will ...