0

I'm trying to do a simple test with Robot Framework where I test python functions and see if they give me the desired results, but I cannot find any good examples documented. I'm giving input and want the test to pass if it meets the expected output that I designate. It would be nice if it could test the return statement of the function. I know that Robot Framework is usually geared more toward acceptance testing and what I'm doing is more aligned with unit testing but it seems like something that should still work with Robot Framework.

Here is an example of some code:

def init(logger_module):

        retVal = 0 # Assuming all goes well.
        #print("module_init - I am in logging module")

        global logging
        logging = logger_module

        initialize_alert_logging()

        #print("The current retVal = {}".format(retVal))
        print(retVal)

        return retVal

I want it to show success if retVal equals 0. Right now I'm able to run a test, but it isn't really testing the output. I think it's just showing that the function actually ran.

Here is my robot file:

*** Settings ***
Library         String
Library         Collections
Library         duplicate_module_simple_logging.py

*** Variables ***
${robotVar}             FooBarBaz
${MY_DATA_TABLE_VALUES_TEMP}            {"foo": "this is foo", "bar": "this is bar"}

*** Test Cases ***
Case1
    init    logger_module

Here is my log file showing a successful test:

1 Answer 1

2

You should just assign the return value of init to a variable.

And then use this variable in a "Should be Equal" (or other check/test)

*** Test Cases ***
Case1
    # WHEN
    ${result} =    init    logger_module
    # THEN
    Should Be Equal    ${result}     0  
Sign up to request clarification or add additional context in comments.

1 Comment

This worked! The only thing I had to modify was I had to use the Should Be Equal As Integers keyword so that it would cast both into integers when comparing them since I think by default it reads variables as strings. Thanks!

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.