21
Salesforce Developer Group Bilbao, 11 de Marzo, 2016

11th Salesforce Developer Group meeting in Bilbao

Embed Size (px)

Citation preview

Page 1: 11th Salesforce Developer Group meeting in Bilbao

Salesforce Developer Group

Bilbao, 11 de Marzo, 2016

Page 2: 11th Salesforce Developer Group meeting in Bilbao

AgendaBienvenidos!! Presentaciones - ¿tenemos nuevos miembros?Unit tests – ApexMocks – David van AlphenDescanso¿Qué os interesa en el próximo SDG?Comunidad

Page 3: 11th Salesforce Developer Group meeting in Bilbao

Bienvenidos!!!¿Qué es SDG? (aka DUG)

¿Nuevos miembros?

Page 4: 11th Salesforce Developer Group meeting in Bilbao

ApexMocksby

David van Alphen

Page 5: 11th Salesforce Developer Group meeting in Bilbao

Dev/Test TheoryOO Principles – SOLID

Dependency Injection

Enterprise Patterns

Separation of Concerns

Mocking / StubbingMockito, NSubstitute, etc

Page 6: 11th Salesforce Developer Group meeting in Bilbao

SOLID Wikipedia - SOLID

SRP – Single Responsibility Principle A class should have one responsibility

O – Open/Closed Principle Open for extension, closed for modification

L – Liskov Substitution Principle Objects should be replaceable by subtypes without affecting correctness of

application

I – Interface Separation Principle Many specific interfaces are better than one general interface

D – Dependency Injection Principle Depend on abstract, not concrete classes

Page 7: 11th Salesforce Developer Group meeting in Bilbao

Dependency InjectionWikipedia - Dependency Injection

No Static methods (workaround available)

Constructors

Setters

Page 8: 11th Salesforce Developer Group meeting in Bilbao

Salesforce & TestingApex tests

System or integration testsUnit tests

Apexmocks framework

Mix and Match

Page 9: 11th Salesforce Developer Group meeting in Bilbao

Mockito vs ApexmocksApex vs Java

No Generics, explicit typing

Concrete classes

Compile on platform

Page 10: 11th Salesforce Developer Group meeting in Bilbao

Apexmocks Generatorinterfacemocks.properties

IMyClass=MyClass:MyParentClassOrInterface

Mocks.cls

.gitignore (or equivalent)

Page 11: 11th Salesforce Developer Group meeting in Bilbao

Code example 1

Page 12: 11th Salesforce Developer Group meeting in Bilbao

Code example 2

Page 13: 11th Salesforce Developer Group meeting in Bilbao

Test StructureGiven

Arrange things needed for the test

WhenTrigger the behavior we want to test

ThenConfirm the results are what we expected

Page 14: 11th Salesforce Developer Group meeting in Bilbao

Code example 3

Page 15: 11th Salesforce Developer Group meeting in Bilbao

Things to AvoidAlways focus on testing public / interface behaviour

Use the framework wisely - don’t verify more behaviour than you need to

Don’t mock too deeply - if you find your unit test having to set up a lot of mocking before you even trigger the behaviour under test, that’s probably a hint that your design could be better

Page 17: 11th Salesforce Developer Group meeting in Bilbao

Questions?

Page 20: 11th Salesforce Developer Group meeting in Bilbao

Sorteo Platform Developer I

Salesforce Certification

Page 21: 11th Salesforce Developer Group meeting in Bilbao

¡¡GRACIAS!!Nos vemos en el

próximo SGD