Test-Driven Development with JUnit and Eclipse

shopfitterpsithurismΛογισμικό & κατασκευή λογ/κού

10 Νοε 2012 (πριν από 4 χρόνια και 5 μήνες)

258 εμφανίσεις

Test
-
Driven Development

with JUnit and Eclipse

John Knight

Blackboard Inc.

And now a word from our lawyers ...


Any statements in this presentation about future expectations,
plans and prospects for the Company, including statements
about the Company, the Building Blocks Program

and other
statements containing the words “believes,” “anticipates,”
“plans,” “expects,” “will,” and similar expressions, constitute
forward
-
looking statements within the meaning of The Private
Securities Litigation Reform Act of 1995.


Actual results may
differ materially from those indicated by such forward
-
looking
statements as a result of various important factors, including:
product development, and other factors discussed in our
Registration Statement filed on Form S
-
1 with the SEC.


In
addition, the forward
-
looking statements included in this press
release represent the Company’s views as of July 26, 2004.
The Company anticipates that subsequent events and
developments will cause the Company’s views to
change.


However, while the Company may elect to update
these forward
-
looking statements at some point in the future,
the Company specifically disclaims any obligation to do
so.


These forward
-
looking statements should not be relied
upon as representing the Company’s views as of any date
subsequent to July 26, 2004.

Definitions


Unit Testing


Automated testing of individual components in isolation from
the rest of the system they are used in.


xUnit


A unit testing framework design that has been ported to many
languages and platforms.


Test
-
Driven Development


A development methodology centered around iterative
development of unit tests simultaneously with new features.

Rationale


Not a testing technique, but a coding technique


Rapid Feedback


Developer Confidence


Better Design


OK, I lied, it is a testing technique

How to Start


JUnit



http://junit.org


Build Scripts



Command
-
line TestRunner



Ant task


IDE Plugins



Eclipse, JDeveloper, Netbeans, IntelliJ, JBuilder…

JUnit Basics


TestCase



One TestCase subclass per fixture (usually one per
production class).


TestSuite



Composite TestCase.


TestResult



Collects the successes and failures in a test run.


TestRunner



Runs a TestCase or TestSuite, reports results.

The TDD Cycle


Ensure all tests
pass


Write a
test

case

The TDD Cycle


Ensure the new test
case fails

The TDD Cycle


Write the simplest
code that will satisfy
the test

The TDD Cycle


Ensure all tests pass

The TDD Cycle


Refactor

The TDD Cycle


Ensure all tests pass

The TDD Cycle


Repeat

The TDD Cycle

Limitations


Poorly Factored Code



Hard to test at the right level of granularity.


External Systems



Can be slow, unreliable, difficult to automate.



Databases



User Interfaces


Non
-
deterministic Functionality



Unit tests should be idempotent.

Advanced Techniques


Stubs/Mock Objects



Simulate slow, unreliable, or uncontrollable components by
providing canned inputs and checking for expected output.


Cactus (In
-
container Testing)



Runs unit tests within a Servlet/J2EE container.



Good for integration testing, may be too slow for unit testing


Test Decorators



Wraps behavior around existing test cases.



JUnitPerf

Further Reading


Websites


http://junit.org


http://www.testdriven.com


http://mockobjects.com


http://jakarta.apache.org/cactu
s


http://clarkware.com/

software/JUnitPerf.html


Books


Test
-
Driven Development by
Example (Kent Beck)


Wiki


http://c2.com/cgi/

wiki?TestDrivenDevelopment

Demonstration