dot net notts js unit testing at microlise

21
JavaScript Unit Testing Adoption in the Enterprise [email protected] - @JonGregory77

Upload: jonathan-gregory

Post on 13-Jul-2015

162 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Dot Net Notts Js Unit Testing at  Microlise

JavaScript Unit Testing

Adoption in the Enterprise

[email protected] - @JonGregory77

Page 2: Dot Net Notts Js Unit Testing at  Microlise

Introduction

• Jon Gregory Technical Architect at Microlise, have been working with .Net since 2.0

• Microlise supply vehicle tracking, telematics and proof of delivery solutions.

• Our approach to adopting JS Unit Testing

Page 3: Dot Net Notts Js Unit Testing at  Microlise

Drivers

• Two Large Web Forms / MVC Hybrid Applications

• Organically grown JavaScript

• Unstructured large JavaScript files

• Increasing use of front end logic

• UX team using bootstrap based UI framework

Page 4: Dot Net Notts Js Unit Testing at  Microlise

State of JavaScript

Page 5: Dot Net Notts Js Unit Testing at  Microlise

State of JavaScript

• In-line JavaScript

• Difficult to read unstructured files

• Multiple JQuery versions

• JQuery selectors binding to the view

• Ball of wool design pattern!

Page 6: Dot Net Notts Js Unit Testing at  Microlise

Unit Testing

Page 7: Dot Net Notts Js Unit Testing at  Microlise

Unit Testing

• Invested heavily in C# Unit Testing

• Benefits in good design & confidence in code

• We wanted the same for JavaScript!

Page 8: Dot Net Notts Js Unit Testing at  Microlise

Challenges

• Perception it wouldn't add value

• Wasn't clear what could be tested

• We hadn't looked at what was possible

• Visual Studio didn't provide the tools

Page 9: Dot Net Notts Js Unit Testing at  Microlise

C# => JS

Friction Free

Page 10: Dot Net Notts Js Unit Testing at  Microlise

Real World

Page 11: Dot Net Notts Js Unit Testing at  Microlise

Evaluation

Page 12: Dot Net Notts Js Unit Testing at  Microlise

Evaluation

• Many tools available

• Community recommended top three

• QUnit, Jasmine and Mocha

• QUnit and Mocha need a mocking framework

Page 13: Dot Net Notts Js Unit Testing at  Microlise

Test Runner

• Needed to be able to run the tests!

• ReSharper plugin available for Mocha but requires NodeJS

• Chutzpah easier and free Visual Studio plugin

• Chose to look at running in Node as a Phase 2

Page 14: Dot Net Notts Js Unit Testing at  Microlise

Approach

• File structure convention

• Mocha Controller added to MVC Applications

• Static HTML

• Training and sample applications

• Visual Studio / Resharper Templates

Page 15: Dot Net Notts Js Unit Testing at  Microlise

File Structure - MVC

/Tests--/app----/ControllerName------/ViewName--------TestFileOne.Tests.js

Page 16: Dot Net Notts Js Unit Testing at  Microlise

File Structure - Logic

/Scripts--/app----/Maths------Calculator.js

/Tests--/app----/Maths------Calculator.Test.js

Page 17: Dot Net Notts Js Unit Testing at  Microlise

Code Demo

Page 18: Dot Net Notts Js Unit Testing at  Microlise

Future

Page 19: Dot Net Notts Js Unit Testing at  Microlise

Future● Looking at ways of adding into out continuous integration & inspection process

● Work to improve JavaScript coding techniques and writing structured JavaScript

● NCrunch Style continuous runner.

● Continuing to promote and train to increase uptake

Page 20: Dot Net Notts Js Unit Testing at  Microlise

Useful Links● https://www.syncfusion.com/resources/techportal/ebooks/javascript

● http://www.sonarqube.org/

● PluralSight – Testing ClientSide JavaScript

● Gil Fink – MSDN – Jasmine Talks

Page 21: Dot Net Notts Js Unit Testing at  Microlise

Questions ?