# You Test? Do Test!

How and where testing fits into your busy dev life.

`brandenbyers.com/slides/youtestdotest`

## What does it even mean to test?

A procedure intended to establish the quality, performance, or reliability of something, especially before it is taken into widespread use.

### Cupellation

Refining process in metallurgy.

The word "test" began to be used in the 17th century in place of "cupel."

Separate "noble" metals such as gold and silver from base metals such as lead and copper.

# Testing is an act of refinement.     ## Chai.js

Assertion Library

• `expect('something').to.contain('thing');`
• `expect('Hello World').to.be.a('string');` ```var add = function (a, b) {
return a + b;
};```
```var add = function (a, b) {
return a + b;
};```
`expect(add(2, 2).to.equal(4));`
```var add = function (a, b) {
return a + b;
};```
`expect(add(2, 2).to.equal(4));`
`expect(add(2, '2').to.not.equal('22'));`
```var add = function (a, b) {
return a + b;
};```
`expect(add(2, 2).to.equal(4));`
`expect(add(2, '2').to.not.equal('22'));`
`expect(add('con','cat').to.not.equal('concat'));`
```var add = function (a, b) {
return parseInt(a) + parseInt(b);
};```
```var add = function (a, b) {
return parseInt(a) + parseInt(b);
};```
`expect(add(2, 2).to.equal(4));`
`expect(add(2, '2').to.not.equal('22'));`
`expect(add('con','cat').to.not.equal('concat'));`
```var add = function (a, b) {
return parseInt(a) + parseInt(b);
};```
`expect(add(2, 2).to.equal(4));`
`expect(add(2, '2').to.not.equal('22'));`
`expect(add('con','cat').to.not.equal('concat'));`
`expect(add(2.22, 2.22).to.equal(4.44));`
```var add = function (a, b) {
return parseInt(a) + parseInt(b);
};```
`expect(add(2, 2).to.equal(4));`
`expect(add(2, '2').to.not.equal('22'));`
`expect(add('con','cat').to.not.equal('concat'));`
`expect(add(2.22, 2.22).to.equal(4.44));`

// AssertionError: expected 4 to equal 4.44

```function numberToRomanNumeral(num) {
var numeral = "";
var arr = [
[1000,"M"],[900,"CM"],[500,"D"],[400,"CD"],
[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],
[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],
[1,"I"]
];
arr.map(val => {
while (num - val >= 0) {
num -= val;
numeral += val;
}
})
return numeral;
}
console.log(7, numberToRomanNumeral(7));
console.log(23, numberToRomanNumeral(23));
console.log(777, numberToRomanNumeral(777));
console.log(1000, numberToRomanNumeral(1000));```
`7 "VII"`
`23 "XXIII"`
`777 "DCCLXXVII"`
`1000 "M"`

edit this code

See the Pen GEwKab by Branden Byers (@brndnb) on CodePen.

## TDD

Test Driven Development

• Red: Write a unit test that fails.
• Green: Write just enough code to make the test pass.
• Refactor: Clean up the code you just wrote.

See the Pen Mozgdm by Branden Byers (@brndnb) on CodePen.

See the Pen MozgRp by Branden Byers (@brndnb) on CodePen.

See the Pen NgEKmG by Branden Byers (@brndnb) on CodePen.

See the Pen PjxYxr by Branden Byers (@brndnb) on CodePen.

## TDL

Test Driven Learning

• Design: Design a code challenge/puzzle.
• All Red: Write full test coverage.
• All Green: Code your solution.
• Break: Try to break your solution.
• Refactor: Refactor your tests to cover any breakage.

• ## Doctors and Lawyers Practice

• • ### Code Challenge Websites  ## Write Kickass Puzzles

Do it for yourself and for the world.

• Step 1: Devise a description.
• Step 2: Generate tests.
• Step 3: Double, triple, and quadrupal check for edge cases.
• Step 4: Solve and bathe in the dopamine.
• Step 5: Share and repeat.