.net - Can I do this in my unit tests? -


I'm not sure what I should do here. Should I have hardcoded all the values ​​or should they have them in any CONST variables?

What was I doing now like this?

In my controller, I had a verification test to check if the user tries to submit a form with empty fields.

Now I have an empty or zero variable for I if this happens I will add the error modelstate which I wrote with an error message.

So in my unit testing I have to make sure that if the blank form variable is submitted that it is caught.

Now in my unit test I have just made a concrete verbal copy and have copied it and pasted the verification message in it.

So in my argument I compare the actual message from the message, how much is stored in my cone, I call it like an ideal state and say the field where I expect error.

Like:

Result. ViewDataModelState ["Username"]. Errors [0];

So if there is a message it would have gone into my code otherwise it will not exist.

So it may have happened to me that I should make a new class. It should be stable and catch all these concert variables.

In this way both controller views and unit tests can use them. In this way, if I need to change the error message, then I just need to change it one place, because I am not testing what the error message is, if it is set I am testing.

The same thing asks for exceptions I have some custom messages, but I am not testing if the message is correct, and the conclusion was caught

The way I I am testing, to see that the message is the message that I expect because this message is not there or the message is not present, something went wrong.

> I am new to the unit testing, so I wanted to make sure that whatever I am going to do, nothing will screw up my unit test.

This makes sense to me, but I thought that the best check first.

Thanks

It is important to write each exam in a manner that is strong Changes in You will often need to change parts of your application to a later date, and every time you do this, there is a risk that you will break one of your more tests.

If your tests are strong to replace, a failed test will actually point to the regression bug.

However, if your tests are called Oster's Scripted Test, then tests may be unsuccessful because of every small change you make in your code base - not because it's a regression bug, but because The test is very brittle, if you do, you lose faith in your tests; Test maintenance takes a lot of time, and in the end you will completely leave the test suite.

As I have read your question, you have already started seeing this anti-pattern shape. I think that is the reason why you do not test for specific lessons, but only this Whether they are being set to everyone or not. I think this is correct - I definitely check for specific strings, but whether or not a string is exactly specified. It makes the test more robust to change, and you avoid osteopesting test anti-pattern.

In many cases, rather than making a condition. Double strings on two strings, you can just use the assurance IsNotNull , or perhaps Assert.IsFalse (string.IsNullOrEmpty (result)) (your platform seems net. ).

Normally, the value is very strong to change so that you want to take a look at the following blog post:

If you feel especially courageous, then I only suggest that you read, many of which I mentioned about patterns and per-patterns. Also good ...


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -