Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7194051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:17:37+00:00 2026-05-28T20:17:37+00:00

I have a small command-line application (about 6k lines). It has no unit tests

  • 0

I have a small command-line application (about 6k lines). It has no unit tests because I didn’t know how to write them; but I’m retroactively adding some now. I read this tutorial but I’m left puzzled about how to test the whole application using this module; in fact, I’m not even sure if what I want to do is called a “unit test”.

Specifically, if I run my application with certain parameters, it is supposed to generate certain output files. I want to make sure those output files are unchanged.

Namely, the following command-line invocations of my application:

main.py config1.txt 100 15
main.py config2.txt def 10 qa
etc.....

create a few small output text files (< 10 MB each) and place them into individual folders (one each per invocation), named such:

output/config1.100.15.201202011733/
output/config2.def.10.qa.201202011733/
etc...

Each folders contains a few small text files (<10MB each). After each iteration of code changes, I’d like to run my application with a few dozen command line parameters, and note any cases where the output files differ. (Ideally, I’d like to do more than that; e.g., for some output files, compare them as tab-separated tables with a certain primary key, so that if row order changed, they will still evaluate as equal; but that’s not critical).

What’s a good way to set this up?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:17:37+00:00Added an answer on May 28, 2026 at 8:17 pm

    Step 1. Break your app into two pieces.

    1. The piece that uses optparse (or argparse) to parse the command-line options.

    2. The piece that does the real work.

    Your “main” script then does part 1 to get all the options and invokes part 2 to do the real work.

    This is called “design for testability” and is the more important part of unit testing.

    Step 2. Once you have two pieces, test the part that does the real work.

    Write unit test scripts that from the_app import the_function_or_class_that_does_real_work

    Test that function or class or whatever that does the real work.

    class Test_With_File( TestCase ):
        def assertFileMatches( self, expected, actual, error=None ):
            # use difflib or whatever to compare the two files.
    
    class TestMain_Sample_File1( Test_With_File ):
        def test_should_produce_known_output( self ):
            with open("temp","w") as target:
                the_function_that_does_real_work( 'config1.txt', arg2=100, arg3=15, out=target )
            self.assertFileMatches( "output/config1.100.15.201202011733", "temp" )
    

    You can write variations on the “TestMain_Sample_File1” class to cover as many test cases as you find interesting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small command-line application written in C that acts as a wrapper/launcher
I wish to have a small dialog based application which is passed command line
I have a little experience developing small command-line applications with Python. I want to
I have a small command line program that uses the Team System API. When
I have a small command line utility project that I'm using Maven to manage.
I have a small command line tool and after running it, I'd like to
I have an application composed of a GUI and 3 launchd daemon launched command-line
I have a small perl script ( found here ) which adds command line
I have been learning C++ in school to create small command-line programs. However, I
I have a small command line app that uses the Oracle client (specifically, Oracle.DataAccess).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.