0

I'm working on unit testing an app I have, but am not using any functions in the app. It only uses command line arguments to know what to do. What would a generic setup be for importing unittest? I'm fairly new to Python and trying to get a hang of it here.

Example, my code could have commands like "app.py configure alpha", "app.py configure beta", "app.py info alpha" - but I'm not entirely sure how this gets referenced in a unit tester.

1 Answer 1

2

If your program has no functions or classes, it has not units, therefore, unit testing is not applicable to it. It will become much more easier to test and maintain the application if you introduce some separation like follows:

def configure(version):
    # do configure things

def info(version):
    # display info

def main(args):
    cmd, version = args[1:]  # add size checking
    if cmd == 'configure':
        configure(version)  
    elif cmd == 'info':
        info(version)

if __name__ == '__main__':
    main(sys.argv)

Now, you can write unit tests for configure() and info() separately.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.