The main purpose of unit testing is to take the smallest piece of testable application in the application, isolate it from the rest of the code and decide if it behaves exactly as expected. Each unit is tested separately before integrating them into the modules to check the interfaces between modules. Unit testing has proven its value in which a huge percentage of defects identified during use.
One simple approach is to make a dummy dataset and data table, give the same column name and try to fill similar kind of values in dataset and table. now use this dataset as sample and test your code with this input.
Please let us know if you feel any problem in making a dataset and testing with it. I like queries and questions. Please ask me.
- public DataTableGetUTLogs()
- {
- DataTable dt = new DataTable();
- try
- {
- //Log_Id
- dt.Columns.Add(new DataColumn("log_id",Type.GetType("System.String")));
- //Log_Type
- dt.Columns.Add(new DataColumn("log_type",Type.GetType("System.String")));
- //name
- dt.Columns.Add(new DataColumn("name",Type.GetType("System.String")));
- dt.AcceptChanges();
- DataRow dr = dt.NewRow();
- //First Row
- dr["log_id"]="12379";
- dr["name"]="xyz inc.";
- dr["log_type"]="ON";
- dt.Rows.Add(dr);
- dt.AcceptChanges();
- //Second Row
- dr=null;
- dr=dt.NewRow();
- dr["log_id"]="13380";
- dr["name"]="usa inc.";
- dr["log_type"]="OFF";
- dt.Rows.Add(dr);
- dt.AcceptChanges();
- //Third Row
- dr=null;
- dr=dt.NewRow();
- dr["log_id"]="12281";
- dr["name"]="abcd inc.";
- dr["log_type"]="ON";
- dt.Rows.Add(dr);
- dt.AcceptChanges();
- return dt;
- }
- catch(Exception ex)
- {
- throw;
- }
- finally
- {
- if(dt != null)
- {
- dt =null;
- }
- }
- }
0 comments:
Post a Comment