By Arastu Shah And Troy Mockenhaupt

warbarnacleSecurity

Nov 5, 2013 (3 years and 5 months ago)

81 views

By

Arastu Shah

And

Troy
Mockenhaupt

“Test
-
first
” programming


Write

a

unit

test

for

a

new

piece

of

functionality

before

the

new

code

is

written


Not relying
solely on a quality
assurance
team


Pervasive(spread throughout) quality
of
testability throughout
the code
base
.


Helps us develop more reusable code


Helps build a cleaner interface


Class B, Class A, assumptions,
dependability





Testing the
servlet


A

servlet

is a Java programming language
class used to extend the capabilities of
servers that host applications accessed via
a request
-
response programming model.
Although
servlets

can respond to any type
of request, they are commonly used to
extend the applications hosted by Web
servers. For such applications, Java
Servlet

technology defines HTTP
-
specific
servlet

classes.


Suppose we need to override the “service()”
method and have it do whatever we want


Several possible outcomes due to growing
complexity of request processing or types of
different requests increase


“Service()” might become too long or break
up into several methods in the class, might
be many utility methods added to
servlet

subclass


Servlets

are extremely awkward to test





Creating instances of
servlets

and testing
individual methods is quite difficult


Different approach with a test
-
first
implementation


Remove the code, that handles request, from
the
servlets

entirely and put it in its own class


Result
-

Design more flexible and
independent of
servlet

technology


Testable design and appropriate division of
labor and more technology
-
independent

Aggressive refactoring: Swapping

technologies using unit tests


Change
code
without breaking
existing
functionality


A
bility
to make major changes
, even
in
integral frameworks, very
quickly


You can even make changes at the very
last moment before delivering the final
product


Author discusses how they removed the
EJB layer

Testing helps remove bugs


Bug count
help pinpoint
areas that need
more testing


Test in area where and when bug found


Make changes in testing framework,
making tests more extensive or
refactor

them


Thus, tests no. constantly grows and
changes. This makes development
faster



Tests as documentation


Authors methodology doesn’t encourage
code comments or code documentation


Infact

relies on tests to document the
system


Reason
-
--
tests written before code so
completely define code


No need for new developers to go through
requirements and design documents


Easier to read a simple test than decipher
complex code



New developers catch up with team quickly


Acceptance tests and their
extensions


Allows product managers to express
and write extensive tests at the scenario
level that are run at every integration


Testing challenges and solutions


Classic
Web application
testing problem is
writing a test that does test both client side
html and
javascript

and application server
testing.


Remedy

1.
First, test parts of the server
-
side code that
are not directly a part of the Web
application.

2.
Second, test parts of the client
-
side code
that have no server interaction

Developed
JsUnit

for
Javascript


3. Write low grain functional tests in the server
-
side language (for example, Java or C++)
that simulate the request/response Web
environment

The test code explicitly invokes the server
-
side
code and the test can inspect the state of the
code, rather than just the HTML output
resulting from the submission.



This
method better than
HTTPUnit


Using this framework, you can write
walkthrough tests that simulate the user
moving through the UI


Walkthrough tests are particularly useful
when writing tests to reproduce bugs that
manual testing has exposed


Testing server output


Goal : Testing the data in the output


Not a goal :
Testing the

webpage look

Two problems


How do you test the data in the HTML
without getting confused with the
cosmetics?


Designers were even less interested in
delving into Java code to change text
color than they had been with JSPs


Solution


Change output into XML and then into
HTML using XSLT


XML is easily testable


Author’s XML contains information about
look of UI and data.

Result


Develop UI a lot faster


Helped separate the untestable web
technology(HTML) from the data





Thank you