Skip to content

Latest commit

 

History

History
130 lines (81 loc) · 2.91 KB

File metadata and controls

130 lines (81 loc) · 2.91 KB

2017-03-27

Agenda

Git

  • Merge conflicts

Where are we now?

  • Bash
  • Git
  • Github
  • Docker
  • Docker Cloud
  • Python Unit Testing

Test-Driven Development (TDD)

Born out of the "Extreme Programming" agile development method.

The basic idea:

  1. Determine what you want your code to do.

  2. Write a new test that checks for the desired functionality.

  3. Run tests. (Should fail the first time.)

  4. Edit/write the code for your new feature.

  5. Re-run tests. If failures still exist, back to 4.

(We did this with the bash koans.)

TDD with docker-cloud-test

Our next step is to start building a running flask server in our Docker container. We'll do this using a test-driven development approach.

Prep your local repository

  1. Make sure it is up to date with any merged pull requests on github.
git checkout master
git pull origin master
  1. Cut a new branch off of master for your TDD flask work.
git checkout -b [branch name]

Create the Test

  1. Alter your run_test.sh file to look like the following:
#!/bin/bash

echo "Running Flask Unit Tests"
python3 unh698_test.py
  1. Create an empty unh698.py file.

  2. Create a unh698_test.py file with these contents:

import unittest

import unh698


class FlaskrTestCase(unittest.TestCase):

    def setUp(self):
        self.app = unh698.app.test_client()

    def tearDown(self):
        pass

    def test_home_page(self):
        # Render the / path of the website
        rv = self.app.get('/')
        # Chech that the page contians the desired phrase
        assert b'UNH698 Website' in rv.data


if __name__ == '__main__':
    unittest.main()

Ensure the test runs, but fails

  1. Commit the changes to run_test.sh, unh698.py, and unh698_test.py to your branch.

  2. Push your branch to your github, and start a pull request.

  3. Add a comment on your pull request with the contents @MathYourLife so I can see how you're doing. Feel free to @mention other students in class to get their help as well. You can find the list here https://github.com/orgs/unh-comp-698-systems-software/people .

  4. Verify that the build in docker cloud attempts to run the python unit tests but fails. You should see an error like

    python3: command not found

Make the test pass

  1. Make changes to either Dockerfile and/or unh698.py to attempt to make the test pass.

Hints:

  • The Dockerfile controls what in installed on the server.
  • The app.py controls how the Flask website will run.
  • Start with changing just the Dockerfile until you can get the python test to actually run.
  • Then move on to setting up the unh698.py file correctly.

References:

  1. Commit and push changes to the github branch. If the test passes, merge and submit a link to your pull request. If the test fails, return to step 4.