Automação de Testes com AngularJS

17
Automação de Testes com AngularJS Rodrigo Branas @ rodrigobranas - http :// www.agilecode.com.br

description

Aprenda a automatizar testes com AngularJS

Transcript of Automação de Testes com AngularJS

Page 1: Automação de Testes com AngularJS

Automação de Testes com AngularJS

Rodrigo Branas – @rodrigobranas - http://www.agilecode.com.br

Page 2: Automação de Testes com AngularJS

“Transformar equipes de desenvolvimento de software”

http://www.agilecode.com.br

Page 3: Automação de Testes com AngularJS

Rodrigo [email protected]

http://www.agilecode.com.br

• Desenvolvendo Software na Gennera• Criando treinamentos na Agile Code• Escrevendo na Java Magazine e PacktPub• Palestrando sobre desenvolvimento de

software em eventos, universidades e empresas

Page 4: Automação de Testes com AngularJS

Certificações

Formação Acadêmica

Ciências da Computação – UFSCGerenciamento de Projetos - FGV

SCJA, SCJP, SCJD, SCWCD, SCBCD, PMP, MCP e CSM

Experiência

Há mais de 12 anos desenvolvendo software naplataforma Java com as empresas: EDS, HP, NET,Citibank, GM, Dígitro, Softplan, OnCast, Senai,VALE, RBS, Unimed, Globalcode, V.Office, Suntech,WPlex e Gennera.

Page 5: Automação de Testes com AngularJS

• Há mais de 5 anos liderando pessoas.• Mais de 2000 horas em sala de aula.• Mais de 100 apresentações em eventos.• 6 artigos escritos para revistas.• 1 livro.• Mais de 500 profissionais treinados.• Criação de 22 palestras.• Criação de 10 treinamentos.• Criação de mais de 3.000 slides.

Page 6: Automação de Testes com AngularJS

controller

Page 7: Automação de Testes com AngularJS

1. angular.module("contatos").controller("contatosCtrl", function ($scope) {

2. $scope.appName = "Contatos";3. });

Page 8: Automação de Testes com AngularJS

1. describe("Contatos Controller Specification", function () {2. var $scope;3.

4. beforeEach(module("contatos"));5.

6. beforeEach(inject(function ($controller, $rootScope) {7. $scope = $rootScope.$new();8. $controller("contatosCtrl", {9. $scope: $scope10. });11. }));

12. it("O nome da aplicação deve ser contatos", function () {13. var expectedAppTitle = "Contatos";14. expect($scope.appTitle).toBe(expectedAppTitle);15. });16. });

Page 9: Automação de Testes com AngularJS

filter

Page 10: Automação de Testes com AngularJS

1. angular.module("contatos").filter("telefone", function () {2. return function (input, separator) {3. return input.substring(0, 4) + separator + input.substring(4);4. };5. });

Page 11: Automação de Testes com AngularJS

1. describe("Telefone Filter Specification", function () {2. var telefoneFilter;3.

4. beforeEach(module("contatos"));5.

6. beforeEach(inject(function (_telefoneFilter_) {7. telefoneFilter = _telefoneFilter_;8. }));9.

10. it("Deve formatar o telefone", function () {11. var telefone= "99999999"12. var expectedTelefone = "9999-9999";13. expect(telefoneFilter(telefone, "-")).toBe(expectedTelefone);14. });15. });

Page 12: Automação de Testes com AngularJS

service

Page 13: Automação de Testes com AngularJS

1. angular.module("contatos").factory("contatosService", function () {2. return {3. calcularImposto: function (valor) {4. return valor*0.10;5. }6. };7. });

Page 14: Automação de Testes com AngularJS

1. describe("Contatos Service Specification", function () {2. var contatosService;

3. beforeEach(module("contatos"));4.

5. beforeEach(inject(function (_contatosService_) {6. contatosService = _contatosService_;7. }));

8. it("Deve calcular o imposto da chamada", function () {9. var expectedImposto = 10;10. expected(contatosService.calcularImposto(100)).toBe(10);11. });12. });

Page 15: Automação de Testes com AngularJS

directive

Page 16: Automação de Testes com AngularJS

1. angular.module("contatos").directive("alert", function () {2. return {3. template: "<div><div>{{topic}}</div><div ng-

transclude></div></div>",4. restrict: "E",5. scope: {6. topic: "@"7. },8. transclude: true9. };10. });

Page 17: Automação de Testes com AngularJS

1. describe("Alert Directive Specification", function () {2. var element, scope;

3. beforeEach(module('contatos'));4.

5. beforeEach(inject(function ($rootScope, $compile) {6. scope = $rootScope; 7. element = angular.element(8. "<alert topic='Something went wrong!'>" + 9. "Please inform the plate and the color of the car" +10. "</alert>"11. );12. var linkFunction = $compile(element);13. linkFunction(scope);14. scope.$digest();15. }));16.

17. it("Should compile the alert directive", function () {18. var expectedElement = "<div>...</div>";19. expect(element.html()).toBe(expectedElement); 20. });21. });