473,386 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Unit Testing and Test Cases

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?

Feb 27 '06 #1
3 1531
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?

Feb 27 '06 #2
MFB
He means unit testing with something like NUnit.

tomb wrote:
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?

Feb 28 '06 #3

"Water Cooler v2" <wt*****@yahoo.com> wrote in message
news:11**********************@p10g2000cwp.googlegr oups.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).


What happens if the offer is zero? Negative? Extremely large? What if the
ages are null? Zero? >100? What if the consideration is unstated? Has no
intrinsic value you can detect?

Feb 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: Christoph Zwerschke | last post by:
In August 2001, there was a thread about the "Art of Unit Testing": http://groups.google.com/group/comp.lang.python/browse_frm/thread/aa2bd17e7f995d05/71a29faf0a0485d5 Paul Moore asked the...
14
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
16
by: Greg Roberts | last post by:
Hi I want to place the tests needed in the code using attributes. There seems to be enough code snippets around for me to cover this. e.g. // Test cases, run these here on the function and...
3
by: Water Cooler v2 | last post by:
Here's my understanding as of now. If I were writing a function bool IsValidContact(Offerer objOfferer, Accepter objAccepter, TermsAndConditions objTermsAndConditions); Before writing the...
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
6
by: Vyacheslav Maslov | last post by:
Hi all! I have many many many python unit test, which are used for testing some remote web service. The most important issue here is logging of test execution process and result. I strongly...
27
by: brad | last post by:
Does anyone else feel that unittesting is too much work? Not in general, just the official unittest module for small to medium sized projects? It seems easier to write some quick methods that are...
10
by: Brendan Miller | last post by:
What would heavy python unit testers say is the best framework? I've seen a few mentions that maybe the built in unittest framework isn't that great. I've heard a couple of good things about...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.