Microsoft Fakes Framework - Unit Testing

Download Microsoft Fakes Framework - Unit Testing

Post on 17-Jul-2015

112 views

Category:

Software

4 download

Embed Size (px)

TRANSCRIPT

PowerPoint Presentation

Testing 2.0Unit Testing Microsoft Fake Framework & Unity IoC

16 Luglio 2014

@felicepescatore

Disciplined Agile Delivery Italy Group

www.felicepescatore.it

1

AgendaTest-Driven DevelopmentUnit testing & TDDMock, stub e shimTesting FrameworkMS FakesDemo

Unit Test Fake lib2

Test-Driven DevelopmentTDD: processo di scrittura del codice in cui lo sviluppo del software guidato dalla stesura di test automatici.

Pensa(Scrivi i tests)Red testsGreen testsRefactorTests must focus on the class' behavior, not its implementation.

http://www.jamesshore.com/Agile-Book/test_driven_development.htmlUnit Test Fake lib3

Testing LanguageSUT - System Under TestDOC -Depend-On ComponentSMELL - "sentore di problema"Code Smell (problemi nel codice) Test Smell (problemi nel test)HollywoodPrinciple: Dontcallus;wellcallyou, alias perIoCalla base del funzionamento deiframework. In unframework(a differenza delle librerie) l'invocazione delle estensioni/personalizzazioni (hotsweetpoint) viene comandato dalframeworkstesso, in funzione a specifici eventi o allo scatenarsi di trigger.Librerie: il proprio codice chiama le librerieFramework: il framework chiama il proprio codice di estension

Unit Test Fake lib4

Unit Testing & TDDUnitFocus sulla classe o sul metodoIsolamentoSeparazioneAutomatizzazioneDa sistemi o moduli esterniTra interfaccia e implementazioneRun ad ogni build

Unit Test Fake lib5

6Mock, stub e Mockhttp://martinfowler.com/articles/mocksArentStubs.htmlStubOggetti preimpostati mediante calls expectations per effettuare la behaviour verification.Oggetti che simulano la logica del sistema per effettuare la state verification.FakesOggetti che implementano linterfaccia delloggetto reale, implementandone parte della logica per effettuare la state verification.Unit Test Fake lib6

shim!Microsoft Windows Application Compatibility Toolkit (ACT)WINELibreria o modulo software che in modo trasparente per lutilizzatore: intercetta le chiamate ad una specifica APIgestisce in autonomia la chiamata stessatrasforma i parametriredirige il flusso di esecuzione.

Unit Test Fake lib7

Stub o Mock?StubMockWarehouseStub warehouse = new WarehouseStub(); warehouse.HasInventory = ()=>{return false};order.fill(warehouse);Assert.IsFalse(order.IsFilled());

WarehouseMock mock = new WarehouseMock(typeof(Warehouse));warehouse.expects(once()).method(HasInventory") .withAnyArguments() .will(returnValue(false));order.fill(mock.Instance);mock.VerifyExpectations();Unit Test Fake lib8

9Framework/Lib .Net per unit testingFrameworkFree/CommercialFeaturesxUnit.netFree (open source)Assertions, AttributesSpecFlowFree (open source)Assertions, Specification DSLNUnitFree (open source)Assertions, AttributescsUnitFree (open source)Assertions, AttributesMSTestFreeAssertions, AttributesLibraryFree/CommercialMocks/StubsTypemock IsolatorCommercialMockTelerik JustMockCommercialMockRhino MocksFree (open source)Mock/StubMoqFree (open source)MockMS FakesFreeStub (mock?)/FakeUnit Test Fake lib9

Microsoft Fakes FrameworkMFF consente di isolare il codice di cui si sta eseguendo il test sostituendo moduli e/o librerie esterne mediante stubs o shims.

Inject interfacesAdd Fakes Assemblies(Create a ShimContext) Construct instances of the stub/shim and provide code for its methods

Unit Test Fake lib10

DemoDEMO: MathLibAdvancedInject interfacesAdd Fakes Assemblies

Unit Test Fake lib11

@felicepescatoreget in touch

Disciplined Agile Delivery Italy GroupFelice Pescatore, Agile Software ArchitectEmail: felice.pescatore@gmail.com

Cell. 392/7157684

www.felicepescatore.it12

ABOUT MEUnit Test Fake lib12THANKS FOR WATCHINGQuest'opera distribuita con LicenzaCreative Commons Attribuzione - Non commerciale 3.0 Italia.

Unit Test Fake lib

MathLibraryAdvanced/MathLibrary/bin/Debug/MathLibrary.dll

MathLibraryAdvanced/MathLibrary/bin/Debug/MathLibrary.pdb

MathLibraryAdvanced/MathLibrary/bin/Debug/Microsoft.Practices.Unity.Configuration.dll

MathLibraryAdvanced/MathLibrary/bin/Debug/Microsoft.Practices.Unity.Configuration.xml Microsoft.Practices.Unity.Configuration A configuration element storing information about a single type alias. Base class for configuration elements with a default implementation of public deserialization. Load this element from the given . Contains the XML to initialize from. Write the contents of this element to the given . The caller of this method has already written the start element tag before calling this method, so deriving classes only need to write the element content, not the start or end tags. Writer to send XML content to. Construct a new, uninitialized . Construct a new that is initialized to alias to the target . Alias to use. Type that is aliased. Write the contents of this element to the given . The caller of this method has already written the start element tag before calling this method, so deriving classes only need to write the element content, not the start or end tags. Writer to send XML content to. The alias used for this type. The fully qualified name this alias refers to. A collection of s. Specialization of that provides a canned implementation of . Type of configuration element in the collection. A base helper class for implementing configuration collections. Type of configuration element contained in the collection. Plug point to get objects out of the collection. Index in the collection to retrieve the item from. Item at that index or null if not present. Plug point to get objects out of the collection. Key to look up the object by. Item with that key or null if not present. Load this element from the given . Contains the XML to initialize from. Returns an enumerator that iterates through the collection. A that can be used to iterate through the collection. 1 Add a new element to the collection. Element to add. Remove an element from the collection at the given index. The index of the item to remove. Remove all the items in the collection. Write out the contents of this collection to the given without a containing element corresponding directly to this container element. Each child element will have a tag name given by . to output XML to. Name of tag to generate. Indexer to retrieve items in the collection by index. Index of the item to get or set. The item at the given index. When overridden in a derived class, creates a new . A new . Causes the configuration system to throw an exception. true if the unrecognized element was deserialized successfully; otherwise, false. The default is false. The name of the unrecognized element. An input stream that reads XML from the configuration file. The element specified in is the element. starts with the reserved prefix "config" or "lock". Gets the element key for a specified configuration element when overridden in a derived class. An that acts as the key for the specified . The to return the key for. Indexer that allows you to get or set an alias by the alias name. Alias of element to get or set. The type name at that alias. A configuration element used to configure injection of a specific set of values into an array. Base class for configuration elements that describe a value that will be injected. Initialize a new instance of . Generate an object that will be used to configure the container for a type registration. Container that is being configured. Supplied in order to let custom implementations retrieve services; do not configure the container directly in thi