Hi
I am not sure what I should be doing here. Should I be hardcoding all the values in or should I have them in a CONST variables. Everything I seen seems to hard code the values in so I am not sure.
Like this is what I was doing now.
Say in my controller I had a validation test to check if the user tries to submit a form with a blank field.
Now I would have a if statement checking for blank or null variable. If this happened then I would add the error to the ModelState with an error message that I wrote.
so in my unit test I want to make sure that if a blank form variable is submitted that it gets caught.
now in my unit testing I just made a CONST varible and copied in and pasted the validation message in.
So in my assert I compare what the actual message is compared to the message stored in my CONST Varrible. I do this by calling like the Model state and call the field up where I expect the error to be.
Like:
result.ViewData.ModelState["username"].Errors[0];
So if the message is there then it must have gone into my code otherwise it would not exist.
So it occurred to me maybe I should make a new class that will be static and hold all these CONST variables.
That way both the controller views and the unit tests can use them. That way if I got to change the error message then I only need to change it one place. Since I am not testing what the error message is I am testing if it gets set.
The same thing say for exceptions I have some custom messages but I am not testing if the message is right, more if the expection got caught.
The way I am testing it though is to see if the message is the message that I expect since if it is not the message or the message does not exist then something went wrong.
I am new to unit testing so I wanted to make sure that what I am going to do won't some how screw up my unit tests.
To me it makes sense but I thought better check first.
Thanks