diff --git a/_sources/python-bdd/TestingSource.py b/_sources/python-bdd/TestingSource.py new file mode 100644 index 0000000..395ea35 --- /dev/null +++ b/_sources/python-bdd/TestingSource.py @@ -0,0 +1,25 @@ +import mainsource + + +class TestingSource(object): + def __init__(self): + self.username = None + self.password = None + self.last_exception = None + + def set_username(self, username): + self.username = username + + def set_password(self, password): + self.password = password + + def create_user(self): + try: + mainsource.create_user(self.username, self.password) + except mainsource.UserCreationError as exc: + self.last_exception = exc + + def is_invalid_password(self): + return (self.last_exception and + isinstance(self.last_exception, + mainsource.PasswordIsNotStrongEnough)) diff --git a/_sources/python-bdd/example.robot b/_sources/python-bdd/example.robot new file mode 100644 index 0000000..8319793 --- /dev/null +++ b/_sources/python-bdd/example.robot @@ -0,0 +1,24 @@ +*** Settings *** +Library TestingSource.py + +*** Test Cases *** +Invalid password + Given that I have a username foo + And that I have a password test123 + When I try to create a user + Then I should get an error of invalid password + +*** Keywords *** +That I have a username + [Arguments] ${username} + set username ${username} + +That I have a password + [Arguments] ${password} + Set password ${password} + +I try to create a user + Create user + +I should get an error of invalid password + Is invalid password diff --git a/python-bdd.html b/python-bdd.html index e99fbe4..55881a7 100644 --- a/python-bdd.html +++ b/python-bdd.html @@ -126,8 +126,7 @@

Código sendo testado

-

-#!/usr/bin/env python
+						
#!/usr/bin/env python
 # -*- encoding: utf-8 -*-
 
 """This is a sample code that simulates a user being created."""
@@ -226,14 +225,153 @@ def main():
 
 
 if __name__ == "__main__":
-    main()
-						
+ main()

Robot Framework

+ + +
+ +
+

Robot Framework

+ +

+*** Settings ***
+Library 	TestingSource.py
+
+*** Test Cases ***
+Invalid password
+	Given that I have a username	foo
+	  And that I have a password	test123
+	 When I try to create a user
+     Then I should get an error of invalid password
+
+*** Keywords ***
+That I have a username 
+	[Arguments]		${username}
+	set username 	${username}
+
+That I have a password 
+	[Arguments]		${password}
+	Set password	${password}
+
+I try to create a user
+	Create user
+
+I should get an error of invalid password
+	Is invalid password
+						
+
+ +
+

Robot Framework

+ +
*** Settings ***
+Library 	TestingSource.py
+ +

Configuração: Indica que deve ser carregado uma biblioteca em + Python (a seguir).

+
+ +
+

Robot Framework

+ +
import mainsource
+
+
+class TestingSource(object):
+    def __init__(self):
+        self.username = None
+        self.password = None
+        self.last_exception = None
+
+    def set_username(self, username):
+        self.username = username
+
+    def set_password(self, password):
+        self.password = password
+
+    def create_user(self):
+        try:
+            mainsource.create_user(self.username, self.password)
+        except mainsource.UserCreationError as exc:
+            self.last_exception = exc
+
+    def is_invalid_password(self):
+        return (self.last_exception and
+                isinstance(self.last_exception,
+                           mainsource.PasswordIsNotStrongEnough))
+
+ +
+

Robot Framework

+ +
*** Test Cases ***
+Invalid password
+    Given that I have a username		foo
+      And that I have a password		test123
+     When I try to create a user
+     Then I should get an error of invalid password
+ +

+ Given, And, When e + Then são palavras reservadas. +

+ +

+ Parâmetros tem que ser separados com Tabs. +

+
+ +
+

Robot Framework

+ +
*** Keywords ***
+That I have a username 
+	[Arguments]		${username}
+	set username 	${username}
+
+That I have a password 
+	[Arguments]		${password}
+	Set password	${password}
+
+I try to create a user
+	Create user
+
+I should get an error of invalid password
+	Is invalid password
+
+ +
+

Robot Framework

+ +
$ robot example.robot
+ ==============================================================================
+ Example
+ ==============================================================================
+ Invalid password                                                      | PASS |
+ ------------------------------------------------------------------------------
+ Example                                                               | PASS |
+ 1 critical test, 1 passed, 0 failed
+ 1 test total, 1 passed, 0 failed
+ ==============================================================================
+ Output:  /Users/juliobiason/personal/presentations/_sources/python-bdd/output.xml
+ Log:     /Users/juliobiason/personal/presentations/_sources/python-bdd/log.html
+ Report:  /Users/juliobiason/personal/presentations/_sources/python-bdd/report.html