|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Unit Testing and Test CasesIf I were writing a function bool IsValidContact(Offerer objOfferer, Accepter objAccepter, TermsAndConditions objTermsAndConditions); Before writing the function, I'd enlist all the conditions that must be met for a contract to be valid. Something along the lines of: 1. There must be a valid offer made by an offerer; 2. There must be an unconditional, voluntary acceptance of the offer; 3. The offerer and accepter must be above the age of minority; 4. There must be a valid consideration (quid pro quo). Though there are many more conditions, for the sake of simplicity, let us stick to only the above four conditions. Going from the above four, I'd translate them into code precondition checks as follows: 1. Assert (objOfferer != null) 2. Assert (objAccepter.Acceptance.IsVoluntary() && objAccepter.Acceptance.IsUnconditional()) 3. Assert ((objOfferer.Age >= ObjLawOfMinority.MinimumAge) && ((objAccepter.Age >= ObjLawOfMinority.MinimumAge)) 4. Assert (objTermsAndConditions.Consideration.Value > 0) These four would be the basis of unit tests after writing code. In the implementation, I'd use Design By Contract (DBC) style assertion: if (objOfferer == null) return false; if (SomeOtherCondition Not Met) return false; Or I might use the straight-forward-one-return-path style design like, if (objOfferer) if (SomeOtherCondition Met) return true; After writing the implementation of the above function, I'd write unit test scripts to test each of the above conditions. These would be seperate functions that would call the function IsValidContract with invalid and valid values against each of the above four conditions we outlined. Now, let me in on some terminology. Which of the above are test cases and what is the unit tests here? None of these are tests at all, they are merely good validation of
parameters in the code. Testing means beating up the application with valid and nonsense data input to verify the application is doing what it is supposed to be doing. Typically, a unit test is performed by the programmer, because he can step through the code while executing and tracking values through the functions, and to verify he hasn't broken anything else that was already working. Test cases are typically performed by QA, or at least someone other than the programmer, ideally with a written test plan and expected results. Tom Water Cooler v2 wrote: Show quoteHide quote >Here's my understanding as of now. > >If I were writing a function > >bool IsValidContact(Offerer objOfferer, Accepter objAccepter, >TermsAndConditions objTermsAndConditions); > > >Before writing the function, I'd enlist all the conditions that must be >met for a contract to be valid. Something along the lines of: > >1. There must be a valid offer made by an offerer; >2. There must be an unconditional, voluntary acceptance of the offer; >3. The offerer and accepter must be above the age of minority; >4. There must be a valid consideration (quid pro quo). > >Though there are many more conditions, for the sake of simplicity, let >us stick to only the above four conditions. > >Going from the above four, I'd translate them into code precondition >checks as follows: > > >1. Assert (objOfferer != null) >2. Assert (objAccepter.Acceptance.IsVoluntary() && >objAccepter.Acceptance.IsUnconditional()) >3. Assert ((objOfferer.Age >= ObjLawOfMinority.MinimumAge) && >((objAccepter.Age >= ObjLawOfMinority.MinimumAge)) >4. Assert (objTermsAndConditions.Consideration.Value > 0) > > >These four would be the basis of unit tests after writing code. > >In the implementation, I'd use Design By Contract (DBC) style >assertion: > >if (objOfferer == null) > return false; > >if (SomeOtherCondition Not Met) > return false; > > > >Or I might use the straight-forward-one-return-path style design like, > > >if (objOfferer) > if (SomeOtherCondition Met) > return true; > > > >After writing the implementation of the above function, I'd write unit >test scripts to test each of the above conditions. These would be >seperate functions that would call the function IsValidContract with >invalid and valid values against each of the above four conditions we >outlined. > >Now, let me in on some terminology. Which of the above are test cases >and what is the unit tests here? > > > He means unit testing with something like NUnit.
tomb wrote: Show quoteHide quote > None of these are tests at all, they are merely good validation of > parameters in the code. Testing means beating up the application with > valid and nonsense data input to verify the application is doing what it > is supposed to be doing. Typically, a unit test is performed by the > programmer, because he can step through the code while executing and > tracking values through the functions, and to verify he hasn't broken > anything else that was already working. Test cases are typically > performed by QA, or at least someone other than the programmer, ideally > with a written test plan and expected results. > > Tom > > > Water Cooler v2 wrote: > >> Here's my understanding as of now. >> >> If I were writing a function >> >> bool IsValidContact(Offerer objOfferer, Accepter objAccepter, >> TermsAndConditions objTermsAndConditions); >> >> >> Before writing the function, I'd enlist all the conditions that must be >> met for a contract to be valid. Something along the lines of: >> >> 1. There must be a valid offer made by an offerer; >> 2. There must be an unconditional, voluntary acceptance of the offer; >> 3. The offerer and accepter must be above the age of minority; >> 4. There must be a valid consideration (quid pro quo). >> >> Though there are many more conditions, for the sake of simplicity, let >> us stick to only the above four conditions. >> >> Going from the above four, I'd translate them into code precondition >> checks as follows: >> >> >> 1. Assert (objOfferer != null) >> 2. Assert (objAccepter.Acceptance.IsVoluntary() && >> objAccepter.Acceptance.IsUnconditional()) >> 3. Assert ((objOfferer.Age >= ObjLawOfMinority.MinimumAge) && >> ((objAccepter.Age >= ObjLawOfMinority.MinimumAge)) >> 4. Assert (objTermsAndConditions.Consideration.Value > 0) >> >> >> These four would be the basis of unit tests after writing code. >> >> In the implementation, I'd use Design By Contract (DBC) style >> assertion: >> >> if (objOfferer == null) >> return false; >> >> if (SomeOtherCondition Not Met) >> return false; >> >> >> >> Or I might use the straight-forward-one-return-path style design like, >> >> >> if (objOfferer) >> if (SomeOtherCondition Met) >> return true; >> >> >> >> After writing the implementation of the above function, I'd write unit >> test scripts to test each of the above conditions. These would be >> seperate functions that would call the function IsValidContract with >> invalid and valid values against each of the above four conditions we >> outlined. >> >> Now, let me in on some terminology. Which of the above are test cases >> and what is the unit tests here? >> >> >> "Water Cooler v2" <wtr_***@yahoo.com> wrote in message What happens if the offer is zero? Negative? Extremely large? What if the news:1141041185.059803.209390@p10g2000cwp.googlegroups.com... > Before writing the function, I'd enlist all the conditions that must be > met for a contract to be valid. Something along the lines of: > > 1. There must be a valid offer made by an offerer; > 2. There must be an unconditional, voluntary acceptance of the offer; > 3. The offerer and accepter must be above the age of minority; > 4. There must be a valid consideration (quid pro quo). ages are null? Zero? >100? What if the consideration is unstated? Has no intrinsic value you can detect?
Did we lose the RadioCheck property on menuitems
Webapplications quits without matter in ASP.NET 2.0 DateTimePicker + DataBinding + Null-Value: THE solution? Is there a simple way to email? What is Instrumentation? ptr to string ? How to remove Volume Name on removable drive? Help please Creating web page of links and content Ado.net to excel ? multi threading error |
|||||||||||||||||||||||