c# - How do I do unit tests in Visual Studio 2015 -


i have below.

using system; using system.collections.generic; using system.io; using system.linq; using system.net; using system.text; using system.threading.tasks;  namespace syncfusion.gitlab {     public class branches     {                  public void createbranch(list<string> projectname, string sourcebranch, string destinationbranch)         {          }                public void createtag(list<string> projectname, string sourcebranch,string tagname)         {          }                public static list<string> getbranchlist(string projectid)         {                      }             public static list<projectdata> getprojectlist()         {          }     }     public class exceloperation     {         public void generateexcel(list<projectdetails> finalexceldata, list<string>projecturl,list<string>tagsorbranchurl)         {          }     } } 

i can able test method , got positive output. not know how test these 2 method public static list<string> getbranchlist(string projectid), public static list<projectdata> getprojectlist()

my sample test code below. below method passed in nunit test.

[testmethod] public void createtags() {     list<string> project = new list<string>();     project.add("test1");     string sourcebranch = "master";     string tagsname = "v1.0.0";     branch.createtag(project, sourcebranch, tagsname); } 

how can test 2 methods?

update:

i can answer of first answer. have anouther doubt.

how test wrong input? mean know input given wrong need green tick mark testing. means input given wrong output wrong therfore testing right.

in below image. need public void getbranchlistforwronginput() green tick mark. enter image description here

how it?

unit testing static method pretty same testing non-static methods. might complex based on logic have in static method.

but simplest way case following.

[testmethod] public void testgetbranchlist() {     string projectid = "someprojectid";     var result = branches.getbranchlist(projectid);     //assert if result has expected result. }  [testmethod] public void testgetprojectlist() {     var result = branches.getprojectlist();     //assert if result has expected result. }  [testmethod] public void testcreatebranch() {     //prepare testdata     list<string> projectname = new list<string> {"someproject"};     string sourcebranch = "sourcebranch"     string destinationbranch = "destbranch";      branches branchesobj = new branches();     // call method passing test data.     branchesobj.createbranch(projectname, sourcebranch, destinationbranch); } 

this should resolve issue.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -