test driven web development with python

341 1.1K 0
test driven web development with python

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... problems are quite common in testing, and there are some ready-made solutions for us in the standard library’s unittest module Let’s use that! In functional_tests.py: from selenium import webdriver import unittest functional_tests.py 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):... That should tell you that functional_tests.py has changed quite substantially: $ git diff diff git a/functional_tests.py b/functional_tests.py index d333591 b0f22dc 100644 - a/functional_tests.py +++ b/functional_tests.py @@ -1,6 +1,45 @@ from selenium import webdriver +import unittest 14 | Chapter 2: Extending our Functional Test using the unittest module -browser = webdriver.Firefox() -browser.get('http://localhost:8000')... (with Selenium), then we go through the basics of Django — models, views, templates — with rigorous unit testing at every stage I also introduce the Testing Goat Part 2 (Chaps 7-13) - Web development essentials Covers some of the trickier but unavoidable aspects of web development, and shows how testing can help us with them: static files, deployment to production, form data validation, database migrations,... self.fail('Finish the test! ') # # She is invited to enter a to-do item straight away [ rest of comments as before] if name == ' main ': # unittest.main(warnings='ignore') # You’ll probably notice a few things here: Tests are organised into classes, which inherit from unittest.TestCase 12 | Chapter 2: Extending our Functional Test using the unittest module The main body of the test is in a method called test_ can_start_a_list_and_re... Testing Goat Obey the Testing Goat! Do nothing until you have a test The Testing Goat is the unofficial mascot of TDD in the Python testing community It probably means different things to different people, but, to me, the Testing Goat is a voice inside my head that keeps me on the True Path of Testing — like one of those little angels or demons that pop up above your shoulder in the cartoons, but with. .. a Functional Test We’ll proceed with nice small steps; we’re going to use Django, which is a popular Python web framework, to build our app The first thing we want to do is check that we’ve got Django installed, and that it’s ready for us to work with The way we’ll check is by confirming that we can spin up Django’s development server and actually see it serving up a web page, in our web browser, on... After you install Python 3, you’ll need to add two directories to your system PATH: the main Python directory (eg c: \Python3 3) and its Scripts subfolder, c: \Python3 3\Scripts You can do this via Control Panel -→ System -→ Advanced -→ Environment Variables There are some instructions at Python. org 3 On windows, Python 3’s executable is called python. exe, which is exactly the same as Python 2 Similarly,... hope, with this book, to install the Testing Goat inside your head too We’ve decided to build a website, even if we’re not quite sure what it’s going to do yet Normally the first step in web development is getting your web framework installed and configured Download this, install that, configure the other, run the script… But TDD requires a different mindset When you’re doing TDD, you always have the Testing... to follow on with this book on Mac, Windows or Linux If you’re on Windows, you can download Python 3 from Python. org If you’re on a mac, you should already have Python 2 installed, but you’ll need to install Python 3 manually Again, have a look at Python. org If you’re on Linux, I trust you to figure out how to get it installed In the last two cases, be clear that you know how to launch Python 3 as opposed... in our functional tests — by forcing us to make a coherent story out of the test, it makes sure we’re always testing from the point of view of the user There is more fun to be had in this area, things like Behaviour -Driven- Development and testing DSLs, but they’re a topic for another book (TODO or maybe an appendix/ chapter at the end?) You’ll notice that, apart from writing the test out as comments, .

Ngày đăng: 05/04/2014, 15:51

Từ khóa liên quan

Mục lục

  • Cover

  • Copyright

  • Table of Contents

  • Preface

    • Why I wrote a book about Test-Driven Development

    • Aims of this book

    • Outline

    • Some pre-requisites

      • Python 3 & programming

      • How HTML works

      • Required software installations:

      • Required Python modules:

      • Conventions Used in This Book

      • Contacting O’Reilly

      • Chapter 1. Getting Django set up using a Functional Test

        • Obey the Testing Goat! Do nothing until you have a test

        • Getting Django up and running

        • Starting a Git repository

        • Chapter 2. Extending our Functional Test using the unittest module

          • Using the Functional Test to scope out a minimum viable app

          • The Python standard library’s unittest module

          • Implicitly wait

          • Commit

          • Chapter 3. Testing a simple home page with unit tests

            • Our first Django app, and our first unit test

Tài liệu cùng người dùng

Tài liệu liên quan