我正在尋找使用Robot Framework來測試.NET應用程序,並且我正在努力瞭解Robot Framework如何實例化C#對象,以用於測試。實例化機器人框架中的C#對象
我與演出的C#應用程序非常簡單:
SystemUnderTest solution
|_ DataAccess project (uses Entity Framework to connect to database)
| |_ SchoolContext class
|
|_ Models project
|_ Student class
|
|_ SchoolGrades project (class library)
|_ SchoolRoll class
|_ AddStudent(Student) method
我想從機器人框架執行傳遞addStudent方法,傳遞應保存到數據庫中的Student對象。
我用Python編寫的測試庫,它使用Python for .NET (pythonnet)調用.NET應用程序:
import clr
import sys
class SchoolGradesLibrary (object):
def __init__(self, application_path, connection_string):
self._application_path = application_path
sys.path.append(application_path)
# Need application directory on sys path before we can add references to the DLLs.
clr.AddReference("SchoolGrades")
clr.AddReference("DataAccess")
clr.AddReference("Models")
from SchoolGrades import SchoolRoll
from DataAccess import SchoolContext
from Models import Student
context = SchoolContext(connection_string)
self._schoolRoll = SchoolRoll(context)
def add_student(self, student):
self._schoolRoll.AddStudent(student)
從Python中調用這個工程:
from SchoolGradesLibrary import SchoolGradesLibrary
import clr
application_path = r"C:\...\SchoolGrades\bin\Debug"
connection_string = r"Data Source=...;Initial Catalog=...;Integrated Security=True"
schoolLib = SchoolGradesLibrary(application_path, connection_string)
# Have to wait to add reference until after initializing SchoolGradesLibrary,
# as that adds the application directory to sys path.
clr.AddReference("Models")
from Models import Student
student = Student()
student.StudentName = "Python Student"
schoolLib.add_student(student)
我有點丟失到如何從Robot Framework做同樣的事情。這是我到目前爲止有:
*** Variables ***
${APPLICATION_PATH} = C:\...\SchoolGrades\bin\Debug
${CONNECTION_STRING} = Data Source=...;Initial Catalog=...;Integrated Security=True
*** Settings ***
Library SchoolGradesLibrary ${APPLICATION_PATH} ${CONNECTION_STRING}
*** Test Cases ***
Add Student To Database
${student} = Student
${student.StudentName} = RF Student
Add Student ${student}
當我運行這一點,失敗,錯誤消息:No keyword with name 'Student' found.
我如何可以創建Robot Framework的一個Student對象,傳遞給學生添加關鍵字?測試中還有其他明顯的錯誤嗎?
C#應用程序使用.NET 4.5.1編寫,Python版本爲3.5,Robot Framework版本爲3.0。
工作就像一個魅力,謝謝。 –