简体   繁体   中英

How do I test a python function using Robot Framework?

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:

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  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM