monadWS
: A Monad-Based
Testing Tool for Web Services
College of Computer, Nanjing University of Posts and
Telecommunications, Nanjing 210003, China
Yingzhou Zhang, Wei Fu, Changhai Nie
j g
A
d
Ab
t
dWS
Agenda
•
About monadWS
•
Monads Techniques
q
•
The monads in monadWS
HSP
d
–
HSP monad
–
Gen monad
–
TestM monad
•
Tool Snapshots
•
Tool Snapshots
•
Conclusion
2About
monadWS
• An automatic WS testing tool based on monads techniques
About
monadWS
An automatic WS testing tool based on monads techniques
•
monadWS
adopts
• HSP monad
[1]for describing WS test cases
• Gen monad
[2]for generating test data automatically,
and
and
•
TestM
monad
for building the whole WS testing.
____________________
[1] HSP (Haskell Server Pages): http://code.google.com/p/hsp/
[2] Cl K H h J Q i kCh k li ht i ht t l f d t ti f
[2] Claessen K, Hughes J. QuickCheck: a lightweight tool for random testing of
Haskell programs. In Proceedings of the Fifth ACM SIGPLAN international Conference on Functional Programming, New York, 2005: 268~279.
It f
k
W SDL Specificat ion <type s/> <bi n di n g/> <s e rvi ce/> <portType/>Its framework
O pe rati on s XML S ch e m a S oapActi on s S e rvi ce s Data G e ne r ation Str ate gy URL addre s sGen
Monads
te s t cas e s (XML fi l e s ) <<Client >> <<Client >> S O AP Ge n e rator S O AP C al l e r re qu e s t s oap HTTP wrap re s pon s e re s u l ts e xpe te d re s pon s e s oap Q u i ck C h e ck Prope rti e sHSP
Monads
TestM
Monads
Test Re portsA
d
Ab
t
dWS
Agenda
•
About monadWS
•
Monads Techniques
q
•
The monads in monadWS
HSP
d
–
HSP monad
–
Gen monad
–
TestM monad
•
Tool Snapshots
•
Tool Snapshots
•
Conclusion
Monads Intro
Monads Intro.
• A general functional notation
A general functional notation
f : a -> b
• Its monadic version of this notion
f: a -> M b
• Operations on monad M
return :: a > M a
return :: a -> M a
bind :: M a -> (a -> M b) -> M b
Therefore, a monad can be thought as a strategygy for combining computations g p into more complex computations.
A
d
Ab
t
dWS
Agenda
•
About monadWS
•
Monads Techniques
q
•
The monads in monadWS
HSP
d
–
HSP monad
–
Gen monad
–
TestM monad
•
Tool Snapshots
•
Tool Snapshots
•
Conclusion
HSP Monad: represent TC
HSP Monad: represent TC
represents a WS test case as a SOAP message
can encapsulate any side effects, and lets all XML
expressions be computed safely
makeTC serv :: InputType
->
HSP
XML
expressions be computed safely
makeTC_serv :: InputType
>
HSP
XML
The input type of a service The input type of a service operation (say serv),
such as String, Double …
HSP Monad: represent TC
HSP Monad: represent TC
makeTC serv :: InputType
->
HSP
XML
For example:
makeTC_serv :: InputType
>
HSP
XML
makeTC_getOffesetUTCTime :: Double -> HSP XML makeTC_getOffesetUTCTime d =
<soap:Envelope xmlns:soap=soapURI xmlns:xsd=xsdURI>p p p p <soap:Body>
<getOffesetUTCTime xmlns=operURL>
<hoursOffset> <% show d %> </hoursOffset> </getOffesetUTCTime> </soap:Body> </soap:Envelope> where soapURI ="http://schemas.xmlsoap.org/soap/envelope/" xsdURI = "http://www.w3.org/2001/XMLSchema" // / / operURL = "http://www.Nanonull.com/TimeService/"
HSP Monad: represent TC
HSP Monad: represent TC
makeTC getOffesetUTCTime :: Double -> HSP XML_g makeTC_getOffesetUTCTime d =
<soap:Envelope xmlns:soap=soapURI xmlns:xsd=xsdURI> <soap:Body>
<getOffesetUTCTime xmlns=operURL>g p
<hoursOffset> <% show d %> </hoursOffset> </getOffesetUTCTime> </soap:Body> </soap:Envelope> </soap:Envelope> where soapURI ="http://schemas.xmlsoap.org/soap/envelope/" xsdURI = "http://www.w3.org/2001/XMLSchema" operURL = "http://www.Nanonull.com/TimeService/" operURL http://www.Nanonull.com/TimeService/
HSP provides interfaces for other computations through the escapes (with “<%” and “%>”)
Gen Monad: generate data
Gen Monad: generate data
automatically generates data for simple types
(such as Double, Int, String and so on)
class
Arbitrary a
where
arbitrary :: Gen a
y
instance Arbitrary String instance Arbitrary Double …
Gen Monad: generate data
Gen Monad: generate data
class
Arbitrary a
where
arbitrary :: Gen a
makeTC_getOffesetUTCTime :: Double -> HSP XML
arbitrary :: Gen a
general testing method:
Step 1 generate a test value
testTCGen :: IO String
Step 1. generate a test value
Step 2. generate the final test case with the value
test CGe :: O St g testTCGen = do
d <- generate (arbitrary :: Gen Double)
return $ hsp2str (makeTC getOffesetUTCTime d)p ( _g )
Gen Monad: generate data
Gen Monad: generate data
makeTC getOffesetUTCTime :: Double -> HSP XML_gtestTCGen :: IO String
general testing method:
testTCGen :: IO String testTCGen = do
d <- generate (arbitrary :: Gen Double)
return $ hsp2str (makeTC getOffesetUTCTime d)
return $ hsp2str (makeTC_getOffesetUTCTime d)
monadic method by
liftM
:
on-the-fly generate
testTCGen2 :: IO String
testTCGen2 =
y
y g
testTCGen2
liftM
(hsp2str. makeTC_getOffesetUTCTime) $
generate (arbitrary :: Gen Double)
Gen Monad: generate data
Gen Monad: generate data
We can easily change the generation strategy
through the instances of Arbitrary class.
class
Arbitrary a
where
arbitrary :: Gen a
y
instance Arbitrary Double where
arbitrary = myDoubleGen arbitrary = myDoubleGen
myDoubleGen :: Gen Double
myStringGen = suchThat arbitrary guard myStringGen suchThat arbitrary guard
where
guard a = (a > 0) && (a < 1000) || elem a [-1, 0, 9999]
14
TestM Monad:
t
ti
d
TestM Monad:
testing as a monad
type TestM
a
processes WS testing as the following
TestM
monad:
Coalgebraic
monad
yp
= CoAlgMonadT
(EnvT TestEnv
g for WS computingEnvironment monad for
t ti
i
t
(StateT TestState
HSP
)) a
testing environment
(eg.
Schema type information,
test cases files
)
)) a
State monad for testing states
CPU Time Results of Autogeneration g Test Cases for TimeService
Execution Time of the Execution Time of the SOAP Messages of
getOffesetUTCTime in TimeService
Comparison of WSTester with Other Test Tools for Web Services Comparison of WSTester with Other Test Tools for Web Services
A
d
Ab
t
dWS
Agenda
•
About monadWS
•
Monads Techniques
q
•
The monads in monadWS
HSP
d
–
HSP monad
–
Gen monad
–
TestM monad
•
Tool Snapshots
•
Tool Snapshots
•
Conclusion
18S
h t
f
t
l
dWS
A
d
Ab
t
dWS
Agenda
•
About monadWS
•
Monads Techniques
q
•
The monads in monadWS
HSP
d
–
HSP monad
–
Gen monad
–
TestM monad
•
Tool Snapshots
•
Tool Snapshots
•
Conclusion
22C
l
i
b i fl i t
d
d b
d t ti
Conclusion
•
briefly introduce our monad-based testing
tool,
monadWS
•
To automatically test web services.
dWS
d
l t d t h l
•
monadWS can use monads related to help
–
WS test case representation,
–
test data autogeneration, and
C
l
i
dWS
d
l t d t h l
Conclusion
•
monadWS can use monads related to help
–
WS test case representation,
–
test data autogeneration, and
–
test auto-execution
–
test auto-execution.
•
Future work
–
More comparisons with existing tools
–
Use more data-generation strategy
g
gy
–