ColdFusion Summit Notes: Testing - How Vital and How Easy to Use, Uma Ghotikar

October 05, 2019

Why is Unit Testing Vital?

  • If no unit or integration testing is in place, we’ll do manual “fuzzy testing” - open the browser, hit some forms, etc
  • this is a very tedious process
  • any small code change, you have to repeat the entire process over again.
  • time consuming
  • probably won’t hit all test cases every time you do that

Jenkins

  • on each build, run these tests
  • instant feedback
  • increases confidence in any code changes

With unit testing in place, we try to break code down into small chunks whenever possible
because of that, you get feedback faster

TestBox

  • open source product
  • free, easy to install
  • lives in /testbox folder
box install testbox
box testbox generate harness

Test Driven Development

  • write the tests first
  • write just enough code to make the test pass
  • if test isn’t passing, keep writing code
  • then refactor code as needed
  • then repeat the cycle

Limitations of TDD

  • very developer oriented
  • tedious as we always have to test methods
  • refactoring is a pain
  • it’s not about verifying software requirements - since it only focuses on functions and verifies that the functions are working correctly
  • neither verifies stakeholder’s expectations nor expresses that requirements are met

Behavior Driven Development (BDD)

  • BDD - emerged from TDD
  • It’s an evolution of TDD
  • still write tests first, but focus on WHAT the system SHOULD do and now on HOW it’s doing it.
  • More info: dannorth.net/introducing-bdd/

BDD example (pseudocode)

function run()
{
scenario( “contact strings” )
.given( “2 input strings” )
.when( “conctat() func is called” )
.then( “concatenated strings are returned” )
.then( “concatenated strings are returned” );
}

you run BDD tests the same way but the output reads more like user stories, more readable, more clear that we’re meeting customer expectations

Story Framework

  • story: we start w a story
  • scenario: we will create scenarios from it
  • specification: then code our spec’s
  • Not testing anything that doesn’t fit in the user story.

BDD lifecycle methods:

  • beforeAll()
  • afterAll()
  • run()
  • beforeEach()
  • afterEach()
  • aroundEach()

Mocking

  • isolating the behavior from other functionality in the app
  • creating objects that simulate the behavior of real objects

MockBox

  • ships w/ TestBox
  • mocking and stubbing capabilities
  • and more

Load Testing

  • important to know what the peak load of the site is
  • ideally before you go into production
  • it’s a type of non-functional testing
  • it is the process that simulates actual user load on an app or website
  • determine how the app behaves during normal and high loads - determine latency throughput, capacity, etc.

JMeter

  • open source, written in Java
  • rich ecosystem
  • supports the Groovy scripting engine
  • record and playback
  • reporting
  • load and performance tests,
  • different apps/server/protocol:
  • http, https, soap / rest, ftp, database via jdbc, ldap, and more

JMeter is not a web browser

  • sends HTTP request
  • the server response
  • but it doesn’t execute JavaScript, etc

Install:

  • install java
    download jMeter
  • extract anywhere on your system
    start it in GUI or CLI mode
    run /bin/jmeter.bat
  • in JMeter:
    create “thread group
    specify how many threads you want to hit yoru site
    add a Sampler - what are we testing, the URL, etc
  • can also run JMeter via CLI
    jmeter -n -t c:\folder\with\my\jmx\settings\file.jmx
  • always run JMeter on a powerful machine - at least 8 to 16 gigs of ram

Slides are on Uma's LinkedIn page
GitHub: GitHub.com/ughotikar/conference2019
Vimeo: vimeo.com/ondemand/intothebox2018