C#: How to TDD a file downloader -
I want to create a simple downloading tool. Give it a list of URLs, a target directory and hit it. This will then download those files and dump them into the target directory enough simple.
But, I would also like to practice TDD. But how would you do TDD in such an application?
Actually the user interface can not be TDD and will be downloaded and written by most common common classes. Which download works, which is a silent container and is not very interesting for TDD ...
How will you make TDD like this application? Or is it an application where TDD really does not understand?
The indicator needs no sign of how and how to start: p
If you are different then you can make TDD user interface heavier application Logic out of user interface This is MVC in short, a conceptual way of doing this is expressed in class diagram (model dropped):
< Pre> + ------------------- --- + 1 | MyDownloadUI + -------------- + + ---------- + ----------- + | | | | Applies. Wei | + ---------------------- + | 1 | {Interface} | 1 1 + -------- + ------------ + | DownloadView + ----- + DownloadController | + ---------------------- + + --------------------- +/ / Code > There is only one thing on the user interface which is to implement the DownloadView
interface and its reference to DownloadController
where it is sent Should it be the action to do this, DownloadController should also have a reference to the DownloadView interface whenever the UI (more specifically, view ) is required to manipulate. Constructors should look something like this:
// sample of MyDownloadUI DownloadController Controller; Public MyDownloadUI {this.controller = New DownloadController (this); // ...} // See DownloadController DownloadView Sample; Public DownloadController (download view view) {this.view = view; // ...}
In this way, the UI can be changed without the controller so that it can be worried about how the scene looks or what are the names of all the labels and lists.
The advantage of this is that you can TDD logic in the download controller and there is a duplicate that changes the UI.
In order to test the actual UI, you do not actually test per unit, this will be a more functional test because the MyDownloadUI link is in conjunction with DownloadController (unless you have no interface for DownloadController ) In this way, for a small project, you can make manual smoking tests whenever you change the UI to the controller or something new.
Whenever you feel that a class is getting very high, you always have the option to break the argument of another class (which makes TDD very easy) you have already given examples , E.g. DownloadTask
, which is clearly an ideal class, so it's a good start then you have FileDownloader
which is DownloadedFile
to FileWriter Sends to
.
DownloadController
I could imagine that this is the only way:
-
goDownload (list & lt; string & gt; Url)
wants to start downloading when MyDownloadUI call
will be one more:
-
addUrl (string url) < -
Clear URL ()
Removes all URLs in internal list -
goDownload (/) )
which takes the list of URLs and "Downloads" ACTION "starts
There are so many TDD tutorials, along with Jean Paul Budu (,) is my favorite video on DNRTV. There is a lot to take in it, but it shows a lot about how to behave in it.
Comments
Post a Comment