Unit Testing Example, on a class with required fields?
- by Mastro
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.