At work I've been asked to increase the amount of code coverage we have in one of our software products. I've never done unit testing before and have read a number of tutorials online; these have been helpful as a starting point but all follow the same pattern - they are testing very simple methods/classes like a calculator or a bank account.
I've found a simple method in our code to start, but the issue is it's still much more complicated than the examples I've read about and I'm unsure where to start. Here's the method:
public static void moveFiles {
string rootDir = ConfigurationManager.AppSettings["RootLoc"];
string dropboxLoc = ConfigurationManager.AppSettings["DropBoxLocation"];
DirectoryInfo dropbox = new DirectoryInfo(dropboxLoc);
folders = dropbox.GetDirectories("*", SearchOption.AllDirectories);
string path = "";
string prevPath = "";
foreach (DirectoryInfo di in folders)
{
FileInfo[] files = di.GetFiles();
foreach (FileInfo fi in files)
{
prevPath = fi.FullName;
string[] p = prevPath.Split(new string[] { dropbox.Name }, StringSplitOptions.None);
path = rootDir + p[1];
fi.MoveTo(path);
}
}
}
I have created a small test method for this:
[TestMethod]
public void GetDirectories_ValidLocation_SetsDropboxLocation()
{
string dropboxLoc = ConfigurationManager.AppSettings["DropBoxLocation"];
DirectoryInfo dropbox = new DirectoryInfo(dropboxLoc);
Assert.IsTrue(dropbox.Exists);
}
Is this along the right lines of what should be tested? Or am I looking at this the wrong way?