开发者

Unit Testing a Windows Scheduled Task Console App

I am in the process of taking over a lega开发者_开发知识库cy system that contains a Console App project, which is run as a Scheduled Task on our production servers. It mainly produces daily and weekly reports, does some database maintenance, etc.

The "main" of the console app handles inputting the command line arguments and determining which of several different processes to execute. Something like

Module MainModule

Public Sub Main()
    '--- Check if command line arguments were specified
    Dim args() As String = Environment.GetCommandLineArgs()
    If args.Length > 1 Then
        ConsoleMain(args)
    End If
End Sub

Public Sub ConsoleMain(ByVal args() As String)
    Dim rc As New Coordinator(enableEmails_)

    Try
        Dim arg_ As String = args(1)
        Dim success_ As Boolean = True

        Select Case arg_.ToUpper()
            Case TaskType.OrderIntegration
                success_ = rc.OrderIntegration()
            Case TaskType.Motivators
                success_ = rc.MotivatorsCreateFile(New CustomerMotivatorsManager)

       ... repeat for each of the various "Task Types"

End Module

What my question is: - This being a Console App with a Main() and ConsoleMain(), I don't seem to have anything that I can access from a Test - i.e. the "Main" and "ConsoleMain" do not appear to be accessible. How can I unit-test something like this, to test the "if argument 'x' is passed, function 'y' is called"?

Thanks in advance,


I'm not sure why Main wouldn't be visible from your tests, unless VB.NET does some behind-the-curtains stuff to hide it.

In any case, why not move your code into its own class(es)? Then you can run unit tests against each class at a time, rather than executing the whole thing at once.

Unit tests usually execute against individual classes, rather than executing the Main entry point of an app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜