-
Notifications
You must be signed in to change notification settings - Fork 102
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
Testing: unit tests #250
Merged
Merged
Testing: unit tests #250
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
1 task
sfount
force-pushed
the
testing-unit-tests
branch
from
April 1, 2016 07:29
a12e72f
to
5b0870f
Compare
This looks awesome. It will be nice to offload some of our end-to-end test work into faster, smaller unit tests. |
This commit introduces the karma testing framework. This will allow us to unit test angular components, directives, controllers, services etc. Unit tests are independent of the BHIMA framework, run very quickly will allow us to test very small units of functionality independent of end to end tests (freeing up end to end tests to focus on more abstract functionality). Karma and angular mocks dependencies are added to package and bower JSON files respectively. `npm install -g karma-cli` can also be run in order to configure the karma server independently of the build process. Example use (independent of build process): `karma start` - starts the karma server and opens up a Google Chrome instance. This is what will power the test .spec.js files `karma run` - runs all karma tests specified in the karma.conf.js Karma is currently configured to watch for and re-run on file changes, any changes to `client/test/unit/**.*.spec.js` will trigger a test run.
This commit updates the previously commited session service unit test; * Updated dependency injection insuring required services are available to the test * Updated framework syntax (expect) to ensure all assertions are compatible with chai * Ensure all tests make logical sense and pass when run in with the `karma` test runner
This commit adds an initial attempt at running a directive unit test. Testing the `bh-integer` directive. The steps for testing a directive: 1. Load the module `bhima.directives` 2. Inject `$compile` and `$rootScope` 3. Compile a basic template including the directive into the root scope 4. Set, update and remove values - make assertions on results This test runner verifies that the Integer validation directive: * validates an integer value * blocks non integer values (string/ decimal)
This commit implements karma unit tests for the bh-unique angular directive. This is included in this pull request to demonstrate key unit test features: * Mocking service responses that are injected into * controllers/directives/services (using $provide) * Proving why separate small components are much easier to test - * mocking up services allows providing guaranteed fake data for more * complex validation (in the unique directive) Testing the more complex $asyncValidators on the directives This test validates that the bh-unique directive responses to two different input: * 'rejects a value that already exists' Value already exists in the mock service (Array) -> $scope model should have no value, form should be $invalid * 'accepts a value that in unique' Value does not exist in the mock service (Array) -> $scope model should exist and equal the input value, form should be $valid
The client side SessionService was updated in a pull request that was accepted into `master`. This test no longer makes sense with the new API and should be re-created to fit the new service.
sfount
force-pushed
the
testing-unit-tests
branch
from
April 4, 2016 10:20
5b0870f
to
6bd6aaf
Compare
jniles
referenced
this pull request
in jniles/bhima
Feb 5, 2017
This commit removes the notify.warn() message that shows if you have been logged in previously and still have a valid session on the client but not on the server. It also improves the speed of the checks by converting them to cached regular expressions. Closes #250.
jniles
referenced
this pull request
in jniles/bhima
Feb 5, 2017
This commit removes the notify.warn() message that shows if you have been logged in previously and still have a valid session on the client but not on the server. It also improves the speed of the checks by converting them to cached regular expressions. Closes #250.
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.
This pull request adds the karma unit test runner as described in #234.
This pull request focusses on demonstrating the testing of services and directives as controllers will mostly act as 'connectors' or 'glue' between these entities - controllers can also be tested using protractor end to end tests.
Unit testing directives and services as shown in this pull request will provide a number of benefits:
Where end to end tests have been used to verify components and directives, small and specific unit tests can be used in their place - this allows for far fewer variables and should increase the number of cases each test can account for
Currently all of our client side testing is done using protractor/ selenium end to end tests - this provides a very broad test recreating the exact environment that BHIMA will run in. Currently these end to end tests take 5 minutes to run on an up to date development machine (Chromebook Pixel 2015).
Unit tests run extremely fast as they do not have to not need to run a server, load all vendor files and bootstrap angular exactly as it would when a client is using it - they are designed to test very specific (and small) pieces of code.
Any end to end tests that are currently designed to test form validation or directives/ components can be removed allowing a focus on more broad module functionality in end to end tests (and removing many of the tests!)
The following components have been tested as examples in this pull request:
directive
:bh-unique
directive
:bh-integer
service
:SessionService
These tests demonstrate how to:
Performance
Tests performed generally put running these 9 tests (testing 3 core components) at taking
0.01
seconds.[2016-04-01 08:38:30.431] [DEBUG] config - Loading config /home/sfount/IMA/BHIMA/bhima-2.X/karma.conf.js Chrome 48.0.2564 (Linux 0.0.0): Executed 9 of 9 SUCCESS (0 secs / 0.009 secs) . Chrome 48.0.2564 (Linux 0.0.0): Executed 9 of 9 SUCCESS (0.109 secs / 0.009 secs)
Session service injection is temperamental across branches - succeeding and failingUpdate: session service test issue caused by re basing withmaster
. Session service was updated with a breaking API change.Add performance metricsCloses #234