Skip to content

Instantly share code, notes, and snippets.

@Shurlow
Last active March 27, 2019 17:57
Show Gist options
  • Save Shurlow/d41378ed540de5dd57caaff40049f80c to your computer and use it in GitHub Desktop.
Save Shurlow/d41378ed540de5dd57caaff40049f80c to your computer and use it in GitHub Desktop.
Testing lesson notes

Testing

Objectives

  • Explain what Unit Tests, Integration Tests and End-to-End tests are
  • Write unit tests for a given problem
  • Describe the difference between TDD and BDD
  • Identify the purpose & tools for Continuous Integration, Code Coverage and Cross-Browser testing

Terms

  • Unit Test
  • Integration Test
  • End-to-End Test
  • Cross-Browser & Device Testing
  • Code Coverage
  • Continuous Integration (CI)
  • Test Driven Development (TDD)
  • Behaviorst Driven Development (BDD)

Resources

Questions

  • What is a Unit Test, in your own words?

    it('should pop items in LIFO order', function() {
      stack.push(1)
      stack.push(2)
      expect(stack.pop()).to.equal(2)
      expect(stack.pop()).to.equal(1)
    })

    Your answer...

  • What is a Integration Test, in your own words?

    const request = require('supertest')('http://localhost:3000')
    
    it('should fetch created user', function(done) {
      request.post('/api/people')
        .send({ name: 'Tony' })
        .expect(200)
        .end(function(res, err) {
          if(err) return done(err)
    
          request.get('/api/people')
            .expect(200)
            .expect(function(res, err) {
              expect(res.body.name).to.equal('Tony')
            })
            .end(done)
        })
      })

    Your answer...

  • What is a End-to-End Test, in your own words?

    it('adds and removes todo items', function() {
      casper.open('http://localhost:3000/')
      
      casper.then(function() {
        this.fill('my-form', { item: 'New Item' }, true)
        expect('.item-label').to.have.text('New Item')
      })
      
      casper.then(function() {
        this.click('.submit-button')
        expect('.item-label').to.not.be.inDOM
      })
      
    })

    Your answer...

  • What parts of your application should you test and what parts should you not test?

    Topics to consider:

    • Constraints
    • Environment Variables
    • HTTP request and status code
    • Page has specific title
    • font size, color etc
    • functions from a third-party library (like underscore)
    • API enpoint permissions
    • API authentication / login
    • Test things you have to check every time you make changes and restart your server?
    • Test elements on your frontend that require manual user acceptance?
  • Given the following addNums function, write a very simple unit test to asses if it works correctly:

    function addNums(a,b) {
      
    }
    
    // tests
    console.log('addNums is a function:', typeof addNums === 'function')

    After you've writen a test, try writing the code for addNums. If you get the test to pass, write another test THEN write more passing code.

    Your answer...

  • How would we write the test you came up with above using an assertion library like Chai or Jest?

    Your answer...

  • With your table, come up with a definition for Test Driven Development (TDD) and Behavior Driven Development (BDD).

    Your answer...

  • With your table try to identify the purpose and tools for Continuous Integration, Code Coverage and Cross-Browser testing?

    Your answer...

  • The following is a very basic example of tested code with Continuous Integration:

    https://github.com/Shurlow/testing-testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment