1. Trang chủ
  2. » Công Nghệ Thông Tin

Pragmatic Unit Testing in Java with JUnit potx

163 1,8K 1

Đ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

Thông tin cơ bản

Định dạng
Số trang 163
Dung lượng 1,19 MB

Nội dung

[...]... existing projects with lots of legacy code Chapter 9, Design Issues then looks at how testing can in uence your application’s design (for the better) The appendices contain additional useful information: a look at common unit testing problems, a note on installing JUnit, a sample JUnit skeleton program, and a list of resources including the bibliography We finish off with a summary card containing highlights... working systems After all, if we aren’t sure the code is doing what we think, then any other forms of testing may just be a waste of time You still need other forms of testing, and perhaps much more formal testing depending on your environment But testing, as with charity, begins at home 1.3 Why Should I Bother with Unit Testing? Unit testing will make your life easier It will make your designs better... list A list of integers * @return The largest number in the given list */ public static int largest(int[] list) { int index, max=Integer.MAX_VALUE; for (index = 0; index < list.length-1; index++) { 5 10 - if (list[index] > max) { max = list[index]; 15 } - } return max; } } Now that we’ve got some ideas for tests, we’ll look at writing these tests in Java, using the JUnit framework 2.2 Testing a Simple... session), run the following class: java junit. swingui.TestRunner You’ll probably be able to run the junit. swingui TestRunner class from your IDE If not, run it from the command line using the jre or java command (as shown) To run a test using the textual UI, as we’ve shown in this book, use: java junit. textui.TestRunner classname For instance, to run the unit tests on the preceding page we’d compile... First Unit Tests, contains an overview of test writing From there we’ll take a look at the specifics of Writing Tests in JUnit in Chapter 3 We’ll then spend a few chapters on how you come up with what things need testing, and how to test them Next we’ll look at the important properties of good tests in Chapter 7 We then talk about what you need to do to use testing effectively in your project in Chapter... has done unit testing before, we hope there will be a couple of nice surprises for you here Skim over the basics of using JUnit and concentrate on how to think about tests, how testing affects design, and how to handle certain team-wide issues you may be having And remember that this book is just the beginning It may be your first book on unit testing, but we hope it won’t be your last Where To Find The... TestLargest .java try { 20 Chapter 3 Writing Tests in JUnit We’ve looked at writing tests somewhat informally in the last chapter, but now it’s time to take a deeper look at the difference between test code and production code, all the various forms of JUnit s assert, the structure and composition of JUnit tests, and so on 3.1 Structuring Unit Tests When writing test code, there are some naming conventions... lowest-level testing that’s designed for us, the programmers There’s plenty of other work to be done in the way of functional testing, acceptance testing, performance and environmental testing, validation and verification, formal analysis, and so on My company won’t let me run unit tests on the live system Whoa! We’re talking about developer unit- testing here While you might be able to run those same tests in. .. production system, for instance) they are no longer unit tests Run your unit tests on your machine, using your own database, or using a mock object (see Chapter 6) If the QA department or other testing staff want to run these tests in a production or staging environment, you might be able to coordinate the technical details with them so they can, but realize that they are no longer unit tests in that context... organizations have grand intentions when it comes to testing, but tend to test only toward the end of a project, when the mounting schedule pressures cause testing to be curtailed or eliminated entirely Many programmers feel that testing is just a nuisance: an unwanted bother that merely distracts from the real business at hand—cutting code Everyone agrees that more testing is needed, in the same way that . engineer should be incorporating into their daily work.” James J. O’Connor III, Lead System Design Engineer Pragmatic Unit Testing in Java with JUnit Andy Hunt Dave. What readers are saying about Pragmatic Unit Testing. . . “This book starts out with a nice introduction discussing what unit testing is as well as why

Ngày đăng: 15/03/2014, 10:20

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN