Unit Testing Example, on a class with required fields?

Posted by Mastro on Stack Overflow See other posts from Stack Overflow or by Mastro
Published on 2010-04-26T16:39:15Z Indexed on 2010/04/26 20:33 UTC
Read the original article Hit count: 159

Filed under:

I'm new to developing Unit test and I can't find an example of how to test an existing class I have.

The class has a save method which does an insert or update in the database when the user clicks Save in the UI. But the save method has required fields that need to be populated. And has other fields that do not.

So how can I run this test properly?
Was trying to write it out..

Give a user
When user saves object
Then Field1 is required
then Field2 is required
Then Field3 is required

WhenUserSavesObject()
object = new object
object.field1 IsNot Nothing

something like that right?

And what about the other fields that are optional? How would I test the save method to make sure it takes all those values properly?

Was trying to use BDD but not sure if I should try it or not.

Can't find any example of classes with many properties that are needed when calling a test method.

© Stack Overflow or respective owner

Related posts about unit-testing