Microsoft Fakes Framework - Unit Testing

Download Microsoft Fakes Framework - Unit Testing

Post on 17-Jul-2015

108 views

Category:

Software

4 download

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 this method. Type of the Validate that an expected attribute is present in the given dictionary and that it has a non-empty value. Dictionary of name/value pairs to check. attribute name to check. Return a unique string that can be used to identify this object. Used by the configuration collection support. 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. 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 this method. Type of the Type of array to inject. This is actually the type of the array elements, not the array type. Optional, if not specified we take the type from our containing element. Values used to calculate the contents of the array. A configuration element representing the namespace tags in the config file. An element with a single "name" property, used for the namespaces and assemblies. 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. Name attribute for this element. A collection of s in configuration. 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. Helpful extension methods when implementing configuration sections that deserialize "unwrapped" elements - elements that should be deserialized into a container but can be present outside that container in the actual config file. Deserialize an element of the given type, store it in the collection object, and Type of element to create and deserialize. Parent element containing element to deserialize. Xml reader containing state to deserialize from. Collection to store the created element into. The created element. Deserialize an element, basing the element type on the one supplied at runtime, and then store the element into the given . This method is useful when reading elements into a polymorphic collection. Base type of element to store. Element that contains the collection being stored into. Xml Reader containing state to deserialize from. Runtime type of element to create. Collection to store the created element into. The created element. Class that tracks the current input state of the parser. A simple implementing of the rules for a Parsing Expression Grammar parsing algorithm. This supplies basic methods to do the primitives of the PEG, and combinators to create larger rules. The PEG "dot" operator that matches and consumes one character. Input to the parser. The parse result. Parse function generator that returns a method to match a single, specific character. Character to match. The generated parsing function. Parse function generator that checks if the current character matches the predicate supplied. Predicate used to determine if the character is in the given range. The generated parsing function. The "*" operator - match zero or more of the inner parse expressions....

Recommended

View more >