-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit Testing #8
Merged
Merged
Unit Testing #8
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…he assertFail syntax
…ario as final transaction test
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
The following development changes were based upon the design article Unit Testing.
Testing is the act of proving a product both works when it is intended to work, and fails under the proper fail conditions. Testing is an extremely important part of any software development cycle. Unit testing is one of the most popular forms of testing, thriving in testing subsystems and individual functions.
In this pull request we implemented 120 different unit tests, proving every important subsystem of the Seed project. The tested segments include cryptography tests, account tests, testing the pseudo-randomness system, testing block creation, transaction creation, the entanglement, the blockchains, the transaction & block squashing mechanism, the ledger, the Seed virtual machine, reading & writing to storage, as well as the messaging subsystem used by UI's. When any test failed, proving a subsystem was not behaving as expected, the subsystem was fixed in order to pass every test.
On top of writing the unit tests, we also created the unit testing environment. This environment allows for the easy addition of future unit tests, as well as allows for logging the test results in both a verbose and non-verbose manner.
Unit Testing Environment
The testing suite is a fairly simple subsystem found in the /seedSrc/tests/unitTesting.js file. This subsystem is composed of two portions, the exported functions and the Test class.
Exported Functions
The exported functions offered are to either run all unit tests, or request data to be used within the tests. Example data's that can be requested are requesting for some sample Transactions or sample Blocks. When users choose to run all unit tests, it will then access all testable subsystems and request from them a mapping of unit tests, and then execute each test.
Test Class
The Test class is a class passed into each unit test upon invocation. The Test class offers functions to tests related to asserting statements, with parameters for error messages if the test fails.
For example,
is a simple usage of the simplest assert method. If the doesEqualFive method returns true, then the test passes. If it returns false, the test fails with the "Five should be equal to five" error message being added as the reason for test fails.
There are other assert overloads, such as assertAreEqual(a, b, errorMessage), created for convenience. However, testing isn't just about testing for success, but also testing for fail. For that reason, there also exists assertFail.
Executes the code passed in as the first function in a try-catch. This assert will consider the test a pass if an error was thrown as expected, however a fail if no error was thrown.
These asserts in the Test class allow unit tests to make multiple checks per unit test.
Implementation
The entire implementation can be found in the /seedSrc/tests/unitTesting.js file. The exported functions allow for the developers to invoke the tests, and for tests to request extra data they may require.
Subsystems which desire to be tested must be added manually to the exported runAllUnitTests function. Each subsystem to be tested must offer a getUnitTests exported functions for the unitTesting system to gather all the unit tests from the testable subsystems.
Unit Tests
In total, fourteen different exports will be extensively unit tested in order to confirm Seed is in fully working order. Afterwards, these unit tests will act as a regression test, allowing us to confirm old functionality still works as intended while implementing future changes.
In each section, we will outline which unit tests are too be created, along with what the procedure for implementing the unit test is.
Cryptography Subsystem Tests
The cryptography tests can be found in the seedSrc/helpers/cryptoHelper.js file.
Account Subsystem Tests
The account subsystem tests can be found in the seedSrc/account.js file.
Random Subsystem Tests
The random subsystem tests can be found in the seedSrc/helpers/random.js file.
Block Subsystem Tests
The block subsystem tests can be found in the seedSrc/block.js file.
Transaction Subsystem Tests
The transaction subsystem tests can be found in the seedSrc/transaction.js file.
Squasher Subsystem Tests
The squasher subsystem tests can be found in the seedSrc/squasher.js file.
Entanglement Subsystem Tests
The entanglement subsystem tests can be found in the seedSrc/entanglement.js file.
Blockchain Subsystem Tests
The blockchain subsystem tests can be found in the seedSrc/blockchain.js file.
Ledger Subsystem Tests
The ledger subsystem tests can be found in the seedSrc/ledger.js file.
Virtual Machine Subsystem Tests
The virtual machine subsystem tests can be found in the seedSrc/virtualMachine/virtualMachine.js file.
File Storage Tests
The file storage tests can be found in the seedSrc/storage/fileSystemInjector.js file.
Local Storage Tests
The local storage tests can be found in the seedSrc/storage/localStorageInjector.js file.
Storage Subsystem Tests
The storage subsystem tests can be found in the seedSrc/storage/storage.js file.
Messaging System Tests
The messaging subsystem tests can be found in the seedSrc/messaging.js file.
References