asp.net - How to write a Unit Test method? -


I'm new to unit testing methods, so can I give unit testing methods for the code given below?

  using the system; Using System.Collections.Generic; Using System.Linq; Using System.Text; Using TIPWebITLibrary.DAL; Public category SearchInfo: IDisposable {public list & lt; SearchResult & gt; {Receive Serial Results; Set; } Public listing & lt; SearchResult & gt; Tag {get; Set; } /// & lt; Summary & gt; /// uses the search string to filter a resultset by serial and tags /// & lt; / summary & gt; /// & lt; Ultimate name = "search" & gt; & Lt; / param & gt; Public SearchInfo (String Search) {SerialResults = New list & lt; SearchResult & gt; (); Tag reflex = new list & lt; SearchResult & gt; (); SerialResults.AddRange (FindSerial (Search)); TagResults.AddRange (FindTags (Search)); } Private Stable IEnumerable & lt; SearchResult & gt; FindTags (string search) {List & lt; SearchResult & gt; result; (Using var db = new TIPWebITDataContext ()) (select result = (i to db.tblTechInventories where i.Tag.Equals (search) select new SearchResult () {SearchType = "Tag", Key = i. Tag, KeyCaption = i.Tag, name = i.tblTechItem.ItemName}). ToList ();} Returning result;} Private static IEnumerable & lt; SearchResult & gt; Search Search (String Search) {List & lt; SearchResult & Select the new SearchResult () search using {searchType = "Searial", Key = (i.e. Serial.Contains) in the db.tblTechInventories (result = (i from db.tblTechInventories) using the variable (var db = new TIPWebITDataContext () I.Tag, KeyCaption = Serial, name = i.tblTechItem.ItemName}). ToList ();} Return result;} #A Sequence IDisposable public implementation of zero (public) {get} ;} Public string name {get} set;}}}   

Can you tell me how to write test methods for the above code?

As anybody making your code you know that its What is the purpose and this is the test for which there are test methods, you want to know that your software behaves in all cases (normal and especially unusual, similar to where you may have to make a creative).

  • How can some parts of my code be called?

  • <

  • What do I expect in each case (separate- Separate parameter / object state)?

    So when you can answer those questions, then typing test methods should be insignificant;)

    To get started One example:

    The only thing I see here publicly available is your constructor and two properties serial results and TagResults So these things are going to be tested (how do I see it for a setter, maybe they should be private, because you Set them in their constructor)

    What different criteria can this Constructor take, and how will it affect the results of your properties? Obviously you want to test for zero values ​​ and empty strings , but maybe some special strings also need to be tested, because They have special functions in your function, which means: white space for example , or you might have some magic string defined anywhere , which can be defined by all of your Unit testing should go into the consideration and later tester Nutrition Methods

    A sample structure of a test method can be as follows:

      [TestMethod] Public Zero TestSearchInfoConstructor () {// Promote something, start something, set Above it;) // Do something with it that produces the result / now emphasizes that if someone is unexpected then it may fail Assert.IsTrue (yourCondition); // Here another trial case may be started ...}    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -