INTRO TO TESTING

OBJECTIVES

  • Discuss why testing is a best practice
  • Explain different approaches to testing
  • Describe different levels of testing and where they fit on the Pyramid of Testing
  • Describe code coverage

why is testing a best practice?

Something that is untested is broken.

  1. Helps you write cleaner code
  2. Helps document code
  3. Helps you get a job
  4. Helps you sleep at night

why is testing a best practice?

Helps you write cleaner code

why is testing a best practice?

Helps document code

describe("Hello World", function() {
  it("should say 'Hello, World!' when ran", function() {
    expect(code.helloWorld()).to.equal("Hello, World!");
  });
});

Does this not tell you exactly what the code is expected to do?

 

Isn't that kind of what docs do?

why is testing a best practice?

Helps you get a job

why is testing a best practice?

Helps you sleep at night

Something that is untested is broken.

Different testing approaches

Test-Driven Development

"Assert" & "Expect"

Makes sense to engineers

Write test code first. THEN the problem-solving code.

Does the code work?

Different testing approaches

"Should"

behavior-Driven Development

Makes sense to whole team

Does the code do what it's supposed to?

Discuss needed behavior with other stakeholders.

Different testing approaches

"Should"

Test-Driven
Development

behavior-Driven Development

"Assert" & "Expect"

Makes sense to engineers

Makes sense to whole team

Write test code first. THEN the problem-solving code.

Does the code do what it's supposed to??

Discuss needed behavior with other stakeholders.

Does the code work?

Do these things need to be mutually exclusive?

Nope

levels of testing

80%

15%

5%

levels of testing

80%

15%

5%

levels of testing

Unit Tests

Should be fast, isolated, and repeatable

Focuses on small pieces of code, typically functions

A strict, written contract that the piece of code must satisfy

Can be automated or manually run

levels of testing

Integration Tests

Can and will use threads, access the database or do whatever is required to ensure that all of the code and the different environment changes will work correctly.

 Focuses on units combined and tested as a group.

Verifies functional, performance, and reliability of features

Can be automated or manually run

levels of testing

UI / functional Tests

Microsoft Typepad has 325 functional requirements.

User testing of functional requirements of program. 

Does this application behave in expected ways? 

webdriver.js is a great tool for functional testing

Code coverage

How much of the program's code is covered by tests?

"Whenever you are tempted to type something into a print statement or debugger expression, write it as a test instead"

-- Martin Fowler

Code coverage is collected by using a specialized tool to instrument the binaries to add tracing calls and run a full set of automated tests against the instrumented product.

Code coverage

While code coverage is a good metric of how much testing you are doing, it is not necessarily a good metric of how well you are testing your product

DISCLAIMER:

Review

Review

  • Helps you write cleaner code
  • Helps document code
  • Helps you get a job
  • Helps you sleep at night

Why test your code?

Review

Red: write the test, run it --> fail

Green: make it pass --> pass

Refactor: make it better

What does red, green, refactor mean?

Review

TDD tests are mostly understood by engineers

 

BDD tests can be understood by most

What is the biggest difference between TDD and BDD? 

Review

Individual functions

What does a unit test test?

Review

Groups of functions, i.e. route handlers

What does an integration test test?

Review

What is the most widely accepted pyramid of testing?

80%

15%

5%

Review

What is code coverage?

How much of your code is tested

Intro to Testing

By Valerie Kraucunas

Intro to Testing

  • 597