Last active
October 26, 2021 15:40
-
-
Save jeffbrl/037efcbc7170581cc558659c4714bdc1 to your computer and use it in GitHub Desktop.
Simple test of a calculator function with the robot framework - v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*** Settings *** | |
Documentation Check arithmetic operations | |
Resource ${EXEC_DIR}/resources/keywords.txt | |
# currently only prints to output.xml | |
Suite Setup math.setup | |
Suite Teardown math.teardown | |
*** Variables *** | |
*** Test Cases *** | |
T1: Adding two integers | |
Verify addition of ${20} and ${5} is ${25} | |
T2: Subtracting two integers | |
Verify subtraction of ${20} and ${5} is ${15} | |
T3: Multiplying two integers | |
Verify multiplication of ${20} and ${5} is ${100} | |
T4: Dividing two integers -- integer result | |
Verify division of ${20} and ${5} is ${4} | |
T5: Dividing two integers -- confirm round down to integer | |
Verify division of ${20} and ${6} is ${3} | |
T6: Subracting two integers that results in negative number | |
Verify subtraction of ${5} and ${20} is ${-15} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import operator as op | |
def setup(): | |
print "setting stuff up" | |
def calculate(number1, number2, operation): | |
arithmetic_function = { '+': op.add, '-': op.sub, '*': op.mul, '/': op.div } | |
return arithmetic_function[operation](number1, number2) | |
def teardown(): | |
print "tearing stuff down" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*** Settings *** | |
Library ${EXEC_DIR}/lib/easy_math.py WITH NAME math | |
*** Keywords *** | |
Verify addition of ${operand1} and ${operand2} is ${result} | |
[Documentation] Verify addition of two integers | |
${calculated_result}= math.calculate ${operand1} ${operand2} + | |
Should Be Equal as Integers ${calculated_result} ${result} | |
Verify subtraction of ${operand1} and ${operand2} is ${result} | |
[Documentation] Verify subtraction of two integers | |
${calculated_result}= math.calculate ${operand1} ${operand2} - | |
Should Be Equal as Integers ${calculated_result} ${result} | |
Verify multiplication of ${operand1} and ${operand2} is ${result} | |
[Documentation] Verify multiplication of two integers | |
${calculated_result}= math.calculate ${operand1} ${operand2} * | |
Should Be Equal as Integers ${calculated_result} ${result} | |
Verify division of ${operand1} and ${operand2} is ${result} | |
[Documentation] Verify division of two integers | |
${calculated_result}= math.calculate ${operand1} ${operand2} / | |
Should Be Equal as Integers ${calculated_result} ${result} |
@bjaishanker, make sure the keywords.txt file exists in resources/keywords.txt and the easy_match.py file exists in lib/easy_math.py.
@bjaishankar Adding parantheses for the print statements seems to solve it. The error output hints about this.
@dmiek That makes sense. I was using python 2.7 at the time I posted this gist.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I got a error saying there is no file names "math.setup". I am new to robot framework, please help me solve this issue.