Is it possible to create a unit test...

Is it possible to create unit test before coding?

If it is possible please provide me an explanation on how to do it...
LVL 8
PagodNaUtakAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:
As the unit test is used to call the methods by providing test inputs and comparing the outputs, I think you need to write the code first and then write the unit tests. It does not make sense other way round.
0
mohammad827Commented:
If you follow proper design steps where-in before writing the code, you have designed the names of classes and methods with exact parameters, etc then you can write your unit test cases but then it will not execute unless you ahve actuall classes and methods.
0
Carl TawnSystems and Integration DeveloperCommented:
Actually if you are working with pure TDD then you would still write the unit test first. The fact you haven't created the classes that the test will use yet means that the test will not compile, which still counts as the test failing. You then write the code required to make the test compile, and pass the test.
0
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

PagodNaUtakAuthor Commented:
>>If you follow proper design steps where-in before writing the code, you have designed the names of classes and methods with exact parameters, etc then you can write your unit test cases but then it will not execute unless you ahve actuall classes and methods.

So, I should create my interfaces first then create testcase?
0
PagodNaUtakAuthor Commented:
Additionaly, it is also mentioned to use Rhino Mocks... any ideas?
0
CodeCruiserCommented:
0
Carl TawnSystems and Integration DeveloperCommented:
More specifically it is a mocking framework. A mocking framework allows you to create dummy dependency objects for your tests. For example, if you were testing an object that returned data from a database you could create a test that injects a mock object into the object that returns a fixed set of data. That way you remove the dependency on the database from the test, and you also more tightly control the data being used in the test.

Remember that your tests have to be consistent and repeatable, otherwise there is little value to them.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PagodNaUtakAuthor Commented:
@carl_tawn,

Can you provide me some example code? A very simple code that can explain the basics...

Regards,

joseph
0
Carl TawnSystems and Integration DeveloperCommented:
Mocking is quite a complex subject and there are tons of samples out there.

This article should help get you started:

    http://www.codeproject.com/KB/dotnet/Rhino_Mocks.aspx
0
PagodNaUtakAuthor Commented:
Please, correct me if I am wrong...

When I use mocking framework I can unit test my interface without creating an actual object yet?
0
Carl TawnSystems and Integration DeveloperCommented:
Yes. You can create a mock object based on the interface.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.