Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
TDD, unit testing and java script testing frameworks workshop
1. Boutique product development company
It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
2. Boutique product development company
It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
Unit Testing, Test Driven Development
and JavaScript Testing Frameworks
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
3. Unit Testing increases the code quality
Unit Testing, TDD and
JavaScript Testing
Frameworks
Testing Types
Overview of Unit Testing
Best Practices
Some Difficult Scenarios
Levels of TDD
Test Driven Development
TDD and Agile
Extreme Programming
Comparison of available JS Testing frameworks
Introduction to Jasmine Framework
Examples
Jasmine Framework practical's
Karma Framework practical’s
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
6. Overview
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
What is Unit Test
–Verifies an atomic piece of code
–Test on specific behavior
–Each test is autonomous
7. Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
8. Why Unit Testing
Consider building a car
from start to finish,
each of the parts which
make the engine, the
chassis, the wheels,
must be individually
verified to be in working
order before they are to
be assembled into a
'car'.
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
9. Unit Tests are written by developers!
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Increase confidence in code
Fearlessly change your code
Discover usability issues early
10. Test is not a Unit if
Interact over parts of system.
Take too much time to execute (>0.01 Sec).
Require Manual Setup.
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
11. Unit Test Best Practices
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
1. Consistent
2. Atomic
3. Single Responsibility
4. Self Descriptive
12. Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
18. Levels of TDD
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
– Acceptance TDD(ATDD)
– Developer TDD
19. Test Driven Development
•Write Test
•Fail the test
•Write Minimum Code
•Pass the test
•Re factor Code
•Meet standards
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
20. Why Test Driven Development
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
21. Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
TDD is not about Testing
TDD is about
–Design and Development
•By testing first you design your code
22. Unit Testing and TDD
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
23. Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
24. Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Rules for Extreme Programming
1. User stories (planning)
2. Small releases
3. Metaphor (standardized naming schemes)
4. Collective ownership
5. Coding standard:
6. Simple design
7. Refactoring
8. TDD
9. Pair programming
10.Continuous integration
11.40-hour workweek
12.On-site customer
26. Comparison of JS Unit Testing Frameworks
Framework Suitable for
Direct access to
JavaScript DOM API
Remote
control
File
watching
File
preprocessing
Tests written
in
Karma
unit yes yes yes yes yes any
JSTestDriver
unit yes yes yes no no JS
Selenium
e2e no yes yes no no any
WebDriver
e2e no yes yes no no any
Jasmine
unit yes yes no no no JS
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
27. Jasmine Framework
• Jasmine is a behavior-driven development framework for testing your JavaScript
code. It does not depend on any other JavaScript frameworks. It does not require a
DOM.
Jasmine API includes features such as:
• A more natural BDD syntax for organizing the test logic than JUnit style assertion
test frameworks
• Asynchronous testing
• Mocks
• Easy to create custom matchers
• Ability to share or isolate behaviors between tests within a spec encapsulating parts
of your spec.
• Continuous integration support
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
28. Jasmine Framework: Syntax
Jasmine aims to be easy to read. A simple hello world test looks like this:
describe('Hello world', function() {
it('says hello', function() {
expect(helloWorld()).toEqual("Hello world!");
});
});
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
29. Jasmine Framework: Test Suite and Test Cases
describe('MyApp Test Suite:', function() { });
• The above “Describe” block defines the test suite in Jasmine, in test suite
single or multiple test cases can be written.
it('Should contain no JavaScript coding errors!', function() {
expect(errorCount).toBe(0); });
• This above “It” block is representing the test cases which can written in
Describe block. Expect showing the expected result for the particular test case.
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
32. Jasmine Framework: Spec and JS Code
A Jasmine test case is written as follows:
// your applications custom code
function addValues( a, b )
{ return a + b; };
// the Jasmine test code
describe("addValues(a, b) function", function() {
it("should equal 3", function(){
expect( addValues(1, 2) ).toBe( 3 ); });
it("should equal 3.75", function(){
expect( addValues(1.75, 2) ).toBe( 3.75 ); });
it("should NOT equal '3' as a String", function(){
expect( addValues(1, 2) ).not.toBe( "3" ); });
});
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
33. Jasmine Framework: Spec Runner (Running the Unit Tests)
Launching the SpecRunner.html file in your local browser runs the tests. Jasmine
provides a nice view of the test results.
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
34. Jasmine Framework: Pros and Cons
Pros:
• Should not be tied to any browser, framework, platform, or host language.
• Should have idiomatic and unsurprising syntax.
• Should work anywhere JavaScript can run, including browsers, servers, phones, etc.
• Shouldn't intrude in your application's territory (e.g. by cluttering the global
namespace).
• Should play well with IDEs (e.g. test code should pass static analysis).
• It should integrate easily with continuous build systems.
• It should be simple to get started with.
Cons:
Not Much examples available
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
35. Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
Basic general test cases
Rainy Days
Sencha Project unit tests
Karma Practical App – ToDo App
Practical Example
36. Jasmine can Use with
• Ruby (with or without Rails)
• Spider Monkey
• Node.js
• JS Test Driver
• Java (with Maven)
• DOT NET
• PERL
• Scala
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer
37. Testing in Angular JS
Sikandar Ahmed | Lead Software Engineer
Ahmad Awais | Software Engineer