3. Different Types of tests
● Unit Tests
A unit test establishes that the code does what you
intended the code to do (e.g. you wanted to add parameter
a and b, you in fact add them, and don't subtract them)
4. Different Types of tests
● Functional Tests
Functional tests test that all of the code works
together to get a correct result, so that what you
intended the code to do in fact gets the right
result in the system.
5. Different Types of tests
● Integration Tests
Is the phase in software testing in which
individual software modules are combined and
tested as a group
Integration tests tell what's not working. But
they are of no use in guessing where the
problem could be.
14. from selenium import webdriver
import unittest
class NewVisitorTest(unittest.TestCase): #
def setUp(self): #
self.browser = webdriver.Firefox()
def tearDown(self): #
self.browser.quit()
def test_can_start_a_list_and_retrieve_it_later(self):
self.browser.get('http://localhost:8000')
self.assertIn('To-Do', self.browser.title) #
self.fail('Finish the test!') #
if __name__ == '__main__': #
unittest.main(warnings='ignore') #
15. from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import unittest
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3)
def tearDown(self):
self.browser.quit()
#It continues below…. next slide
16. # We continue here...
def test_can_start_a_list_and_retrieve_it_later(self):
# Edith has heard about a cool new online to-do app. She goes
# to check out its homepage
self.browser.get('http://localhost:8000')
# She notices the page title and header mention to-do lists
self.assertIn('To-Do', self.browser.title)
header_text = self.browser.find_element_by_tag_name('h1').text
self.assertIn('To-Do', header_text)
# She is invited to enter a to-do item straight away
inputbox = self.browser.find_element_by_id('id_new_item')
self.assertEqual(
inputbox.get_attribute('placeholder'),
'Enter a to-do item'
)
25. def test_home_page_can_save_a_POST_request(self):
request = HttpRequest()
request.method = 'POST'
request.POST['item_text'] = 'A new list item'
response = home_page(request)
self.assertEqual(Item.objects.count(), 1) #
new_item = Item.objects.first() #
self.assertEqual(new_item.text, 'A new list item') #
self.assertIn('A new list item', response.content.decode())
expected_html = render_to_string(
'home.html',
{'new_item_text': 'A new list item'}
)
self.assertEqual(response.content.decode(), expected_html)
26. def test_home_page_can_redirect_after_POST(self):
request = HttpRequest()
request.method = 'POST'
request.POST['item_text'] = 'A new list item'
response = home_page(request)
self.assertEqual(Item.objects.count(), 1)
new_item = Item.objects.first()
self.assertEqual(new_item.text, 'A new list item')
#Redirect instead of template
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], '/') #W