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?
 
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
 
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.