Professional Documents
Culture Documents
f yo('re any good, w&y not *(st write proper+correct code ) Specs, typos, and , levels of comple-ity .ven wit& perfect code, we cannot control all o(tside variables /inder, c&ap. 01 2 Small C&allenge, 34 perm(tations 5ollison, S6 Test 7 Perf, p.881 Using only the characters 'A' - 'Z' the T&e virt(e of t&e pragmatist approac&
total number of possible character combinations using for a filename with an 8-letter filename and a 3-letter extension is 268 263! or 2"8!82#!"$$!#28%
"nit
/lac< bo-, w&ite bo-, grey boS&ared memory, s&ared interfaces, s&ared messages Load testing, performance testing, regression testing
ntegration
Precondition=postcondition, load, regression Man(al >e.g. ;" ?, a(tomated >e.g. @ormal ver.?
2cceptance testing
@ormal approac&es
/inder, c&ap.3, combinatorial1 en(merate, c(ll, verify, impractical, &(mbled by comple-ity /inder, c&ap.A, state mac&ines1 flow vis(aliBation, co&erence >p.#8%?, (sef(l as cscw artifact /inder, c&ap.,C04, patterns1 templates for test design, good craftsmans&ip, tools of t&e trade, &e(ristics in a combinatorial e-plosion. 5ecogniBing t&e facts. Test often, test repeatedly, test a(tomatically
2gile approac&
TDD testing
C an agile approac&
Simple recipe
Design as re:(ired 6rite some test cases See t&at t&ey fail >no code yet to e-ercise? Ma<e t&em pass by writing compliant code ;oto start
6rite iteratively, code and design iteratively ;rad(al improvement t&ro(g& design and selection D evolving design E code
TDD testing
Concise Self c&ec<ing 5epeatable 5ob(st S(fficient Fecessary Clear .fficient Specific ndependent Maintainable Traceable
Sealed interfaces in legacy code M(ltit&readed designs wit& intricate loc< patterns Deeply tiered implementations wit& no separation 2(tomated ;" testing >allow for scripting, please? Mismanagement, b(siness decisions Database dependencies >consider moc< ob*ects? Gverly long and comple- test cases D easier to cran< o(t t&an yo( mig&t t&in<... /(gs in testing &arnesses and framewor<s
Pragmatic testing
Test to falsify D not to validate. Prove false, not tr(e Prove beyond a reasonable do(bt. ;ood eno(g& for &anging, good eno(g& for testing. Strategic levels of testing >not systemic levels?
Test e-&a(stively Test e-ploratorily Test sporadically Test stoc&astically 5oll yo(r own
.:(ivalence classes D formal and &e(ristic /o(ndary val(es D pea<s and valleys rat&er t&an flatlands 5is< analysis D (nclear, comple-, legacy, &ere be dragons "se coverage tools D w&ic& portions of code e-ercised1 Fcover .-perience and int(ition
Tools
H(nit F(nit = Fcover = Fant >versatile, ;" , convenient, e-tendible? /oost >organise into cases, s(ites, e-tensive assert library, simple and effective? Cpp"nit >e-tending framewor< base classes, assert library, cl(msy?
namespace ban< I (sing SystemJ (sing F"nit.@ramewor<J LTest@i-t(reM p(blic class 2cco(ntTest I 2cco(nt so(rceJ 2cco(nt destinationJ LSet"pM p(blic void nit>? I so(rce + new 2cco(nt>?J so(rce.Deposit>#$$.$$@?J destination + new 2cco(nt>?J destination.Deposit>04$.$$@?J K LTestM p(blic void Transfer@(nds>? I so(rce.Transfer@(nds>destination, 0$$.$$f?J 2ssert.2re.:(al>#4$.$$@, destination./alance?J 2ssert.2re.:(al>0$$.$$@, so(rce./alance?J K
== P dP Qincl(de NStd2f-.&N Qincl(de N..=FSvn.Core=ManagedPointer.&N Qincl(de Nmanagedpointertest.&N Q(sing Smscorlib.dllT (sing namespace SystemJ namespace I void void@(nc> voidU ptr ? I StringU string + U>staticRcastSFSvn11Core11ManagedPointerSStringUTU T> ptr ? ?J 2ssert112re.:(al> string, SNMoo worldN ?J K K void FSvn11Core11Tests11MCpp11ManagedPointerTest11Test/asic>? I StringU str + SNMoo worldNJ ManagedPointerSStringUT ptr> str ?J ==c&ec< t&at t&e implicit conversion wor<s 2ssert112re.:(al> ptr, SNMoo worldN ?J ==implicitly convert to voidU void@(nc> ptr ?J
void FSvn11Core11Tests11MCpp11ManagedPointerTest11Test2ssignment>? I StringU str + SNMoo worldNJ ManagedPointerSStringUT ptr0> str ?J ManagedPointerSStringUT ptr#> SN/le&N ?J ptr# + ptr0J 2ssert112re.:(al> ptr0, ptr# ?J 2ssert112re.:(al> ptr#, SNMoo worldN ?J
K void FSvn11Core11Tests11MCpp11ManagedPointerTest11TestCopying>? I StringU str + SNMoo worldNJ ManagedPointerSStringUT ptr0> str ?J ManagedPointerSStringUT ptr#> ptr0 ?J 2ssert112re.:(al> ptr0, ptr# ?J
Solution Implement a class CallStac&'racer, that internally traces the call stack, (ut writes to the de(ug trace only, if an exception has occurred. he mechanism is as follows> 7n instance of the class is (ound to a (lock (this works for at least C?? and "mall alk!. he constructor for that instance takes as a parameter information a(out where the instance has (een created, e.g. file name and line num(er. If e%erything is @A, at the end of the (lock, the function "etComplete(! is in%oked on the instance of CallStac&'racer. 6hen the instance goes out of scope the destructor is called. In the implementation of the constructor, the instance checks, whether the "etComplete(! function was called. If not, an exception must ha%e (een thrown, so the destructor of the instance writes the information, e.g. file name, line num(er, etc., to the de(ug trace. If the "etComplete(! function was called (efore, then the instance traces nothing thus a%oid the <noise= in the de(ug trace. class CallStackTracer { CallStackTracer(string sourceFileName, int sourceLineNumber) { m_sourceFileName = sourceFileName; m_sourceLineNumber = sourceLineNumber; m_bComplete = alse; }; !CallStackTracer() { i ( "m_bComplete ) { cerr ## m_sourceFileName ## m_sourceLineName; } } $oi% SetComplete() { m_bComplete = true; } pri$ate& string m_sourceFileName; int m_sourceLineNumber; }; '' Some co%e to be co$ere% b( a CallStackTracer $oi% oo() { CallStackTracer cst(__F)L*N+,*__, __L)N*N-,.*/__); '' all normal co%e goes 0ere1 cst1SetComplete(); } Note, that BBCID+N74+BB and BBDIN+N*49+EBB are preprocessor macros in C??, which will (e replaced during compilation (y their %alue.