Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce unittest #11

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from

Conversation

marqh
Copy link

@marqh marqh commented Feb 1, 2017

Hi @katyhuff @gvwilson

this is a replacement for
swcarpentry#2

targeting this repository; as requested

@katyhuff
Copy link
Collaborator

katyhuff commented Feb 1, 2017

Thanks @marqh ! I'll have time to look this over on friday. Talk to you then.

@katyhuff
Copy link
Collaborator

katyhuff commented Feb 16, 2017

Sorry, @marqh . This fell off of my radar. I will look this weekend at this. For real this time.

Copy link
Collaborator

@katyhuff katyhuff left a comment

I'm really sorry @marqh that this took a long time. Generally, I just think an explanation at the beginning to explain why and when someone might want to know unittest in addition to pytest, would be appropriate. Also, a couple of line length and brit->american spelling suggestions follow. Thanks for the contribution!

@@ -1,159 +0,0 @@
<!DOCTYPE html>
Copy link
Collaborator

@katyhuff katyhuff Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this file deleted?

@@ -1,114 +0,0 @@
<!DOCTYPE html>
Copy link
Collaborator

@katyhuff katyhuff Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this deleted?

> -
> -

The Python standard library provides a module for writing and running tests, called `unittest`, which is documented for [Python3.6](https://docs.python.org/3.6/library/unittest.html?highlight=unittest#module-unittest) and [Python2.7](https://docs.python.org/2/library/unittest.html?highlight=unittest#module-unittest).
Copy link
Collaborator

@katyhuff katyhuff Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long. Please keep lines, even text, under 80 chars.


The Python standard library provides a module for writing and running tests, called `unittest`, which is documented for [Python3.6](https://docs.python.org/3.6/library/unittest.html?highlight=unittest#module-unittest) and [Python2.7](https://docs.python.org/2/library/unittest.html?highlight=unittest#module-unittest).

This module is useful for writing all styles of test, including unit tests and functional tests.
Copy link
Collaborator

@katyhuff katyhuff Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already cover pytest, perhaps this would be a good place to justify the need to learn both (or when it is or is not necessary to learn both). My general feeling is that pytest is much more friendly to beginners.


## Functional Tests

Functional testing is a way of checking software to ensure that it has all the required functionality that's specified within its functional requirements. This will test many methods and may interact with dependencies like file access.
Copy link
Collaborator

@katyhuff katyhuff Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line length.


## Unittest TestCases

unittest is part of the Python core library; it defines a class, unittest.TestCase which provides lots of useful machinery for writing tests. We define classes which inherit from unittest.TestCase, bringing in their useful behaviour for us to apply to our tests.
Copy link
Collaborator

@katyhuff katyhuff Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line length


unittest is part of the Python core library; it defines a class, unittest.TestCase which provides lots of useful machinery for writing tests. We define classes which inherit from unittest.TestCase, bringing in their useful behaviour for us to apply to our tests.

The reuse of objects in this way is a really useful programming approach. Don't worry if it is new to you. For testing with unittest, you can just think of it as a framework to fit your test cases into.
Copy link
Collaborator

@katyhuff katyhuff Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line length


The reuse of objects in this way is a really useful programming approach. Don't worry if it is new to you. For testing with unittest, you can just think of it as a framework to fit your test cases into.

We can rewrite the tests from the previous page, using the Unittest approach.
Copy link
Collaborator

@katyhuff katyhuff Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line length. Otherwise, great transition.


~~~

Unittest reports failures and errors on test cases, which we can see if we run Python2, as one of our tests only passes in Python3:
Copy link
Collaborator

@katyhuff katyhuff Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line length


## Unittest

The `unittest` module also provides this functionality for us with the `setUp` and `tearDown` methods that allow you to define instructions that will be executed before and after each test method (note the capitalisation of these names, which is important).
Copy link
Collaborator

@katyhuff katyhuff Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps you can use the notion of "fixtures" here, so that the student recognize the vocabulary that they just learned in the previous lesson?

Copy link
Collaborator

@katyhuff katyhuff Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line length.

@katyhuff
Copy link
Collaborator

katyhuff commented May 4, 2017

Hi @marqh , have you been able to look at these change requests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants