Create tool which allows to set componentes state. This allows to either check the state of the components in a TDD classic style test or to check the behaviour by testing that the tool was called with the right parameters.
miércoles, 30 de septiembre de 2015
Testing ui ciboodle
Premisas ciboodle dev
Logic place within a form process cant be reused. Not good to put logic in a place that you can't reuse it.
You test mainly logic.
when you test the through the ui you are testing the most end to end test, the most black possible black box.. However you'll need to stub or mock some object in order to get the behaviour you want. Which means not testing directly the object that implements it youll have to configure quite a lot in your test, which at this point you don't have a black box test anymore because you are configuring the inside of the ui. Although you could use factories to encapsulate that knowledge
Form processes can be tested as any other object. However if make sense
--> which means we test them as a black box, without looking at who he delegates to.
Testing at the form process level is more end to end test. It covers more code
martes, 29 de septiembre de 2015
London School Vs Classical TDD
One of things Emily mentions which I have experimented is the fact of not writen gold-plating code. It happens recently while developing the comparator. I have started developing the core classs "Comparator". I had to constantly remember myself that this class will not be called in certain way because the button in the UI will be disabled if, for example, both policies are not entered.
So I definetely see an advantage of working outside in from the requirements and write just the code that does the job.
Action entitlement manager
In a call center application one of the key/core aspects is the user entitlements which determine given a user what can and cannot this user do.
Another reason for an action to be available can depend on the entity which that action belongs to. For example you might not to edit a policy if the policy is already closed.
So that's two different reasons to determine if action is available: the entitlement and the action entity or context in which the action is carried over. Its quite possible that these reason are handled in different ways. Entitlement failure, can be handled simply by hiding the functionality. While context failure can be handled with an informative error message.
Again is important to determine same simple error code object which allow to handle the failure in different ways.
Again this can fit within the generic validator, handler approach. Where a composed validator can be created, and them invoked by passing the handler which can be composed one too;one generic handler which handles the failure hiding a parametrized form component. And one popup error message handler which displays the failure message for the context failure.
viernes, 25 de septiembre de 2015
Registering listeners into services
I have just finished what it could be one of my last developments in my current client, the false new business comparator. One screen which based on a renewal proposal and fnb proposal compares them and return a lost of the fields which are different. The design is an FnbComparator class which acts as the core of this screen. This class has a fnbcomparator service which does job of getting the info from the db an compare it returning a list of differences. The fnbComparator has a Compariaosn translator which transforms the service reaponses into calls to a listener, which is implementes by the displayer. The main class remains like this:
Displayer = new FnbComparatorDisplayer()
New FnbComparator(displayer,new FnbComparatorService(), new FnbComparatorTranslator(displayer)
Displayer and comparator have each other references to allow call backs.
Responsibilities remain like this:
FnbComparator displayer: allows the user to enter info and it triggers the behavior on the comparator main class.
FnbComparator: its the class which supports the screen behavior. Expose methods accordingly to the fields shown in the displayer. It does the validation and send messages back to a listener (the displayer in this case) with whether or not that operation succeed.
There might be another way to look at his responsibilities; This class expose and interface which allows to set the correct information to compare two prp, and them expose the method compare. Each of this methods produces output messages to a class listener. However notice how the interface its dictated by the neccesity of the screen:
Setfnb(fnb fnb)
Setrenewal(renewal renewal)
Setfnbbyprposalno(string prpno)
Compare()
Notice those methods support the selection of a renewal, selection of a fnb and the manual entering of the fnb number from the ui. So he is really acting as screen listener.
Comparator service
In order to provide the screen support, the FnbComparator needs something that does the comparison, is clear this responsibility.
Notice an interesting thing this service returns a response to itscaller (FnbComparator) who is in charge of handling the response. He does it by using a response translator which allows yo hide the internals from the respond and it sends accordingly output messages (compared, unknownerror, different vehicles...) That means the respond error code system can change and we only have to change this class. It exchanges the error codes for output messages. That job is done in the book 'growing objects orientated systems" by registering the translator within the chat (my comparator service). This allows the FnbComparator remain ignorant from the fact that he needs a "servicerespondtranslator" combined with the service. Its not obvious that you need this translator to do that. It would be if the service ask for it.
This design of registering listeners seems emerging when we do outside in development. If youll start thinking from the inside out...
It seems useful when calling a service which can have multiple outputs. This way you can have one class which manages this outputs and converts them into messages creating a nice interface.
Other approach will the caller getting the response. This might bbe more the casa when the call returns more of a concrete answer, like a calculation, which then its used by the caller to calculate something else that you can assert on the final calculation.
However im this scenario the next step will be to enable or disable the buttons. Which is not the responsabilty of the caller. So you'll have to create too many classes for this test.
One approach will be pass the displayer as a listener and asserts that the displayer calls some util action. Class. With an interface very specific like 'disable button compare'. In this case given a service call you could test almost till the last step of the ui logic. As much fine grained are method in the ui as more logic you can test leaving only without testing the line of code which sets CSS class or calls the disabled. Method on the button
Bottom line is that testing state in ui is difficult and that's why we look for this mesage approach.
miércoles, 23 de septiembre de 2015
TDD - motivations
- You are not allowed to write any production code unless it is to make a failing unit test pass.
- You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
- You are not allowed to write any more production code than is sufficient to pass the one failing unit test.
- Halve your debugging time
- Serve as documentation
- Improve you designs
- Its fun
Halve your Debugging time
Following the three rules you'll never be more than a minute away from knowing that you code works. You can easily undo the last line you when something doesn't work
Serve As Documentation
Third party come with a pdf guide. What is the part that we really look at? The sample codes. Unit test are simple to understand, they show every possible way to invoke an API, and they are executable, so they are always in sync, they are the perfect documentation!!
Improve your design
Writting test after your works it's quite hard because the code is not testable, its too coupling to something, and its hard to break that coupling.
Following the laws you can't write production code that is hard to test, because you wrote the test first. "Your code is testable or decouple, simply by writing the test first you end up you wind up your production code in ways that you never thought before. You end up with a better design".
Its fun
Becuase the test fail and you want to make it pass. You get to write a test and make it pass, write another test and make it pass...
Main reason
Bad code,
why do you write it? we have to go fast.
Why don't you clean it? How many times you look at a code and think I need to clean it, next thought is I don't want to break it?
You are scared from breaking it. If you break you own it. So you don't touch it. So system continues to get worse and worse, slowing you down, slowing your team down till eventually the project gets through away and fresh new project starts.
How do we get reed of that fear?
Imagine we have a button, and when you push it within a few seconds a green light will tell you everything works.
"If you have the button, you'll not be afraid of touch, if you touch it will get clean, if it gets clean the team will go faster and thats why we do it."
How is stupid is to be scared from the code write, how bad is to not make a change that improve you code, how unprofesional?
The only way is to have a suite of test that you can trust. You can trust your unit test if test everything.
Code coverage tool?
The goal is a 100%. You can't reach it but we try to get as close as possible.
jueves, 17 de septiembre de 2015
Practical object oriented -Sandi metz
I've finished today the book. Just to write a list of the top things within the book:
Asking for what instead of telling how
Seeking context independence
She uses the example of mechanics and Trip. Where a trip is prepare if its bikes are prepare. There are two knowledge levels here. One is how to prepare a bike (pump the tires, check chain...). The other is how to prepare a trip. Which is by preparing each of his bikes. Both responsibilities correspond to the Mechanic. In order todo that a mechanic knows that a trip has bikes. But we could abstract this concept into a preparable , where something can be preparable is it has bikes. This avoids the preparing knowledge from leaking into the trip class.
Notice that in order to achieve this we have to different kinds of interfaces. On one side we have a mechanic (preparator), exposes command methods, which allow to tell the what not the how. But on the other we have something preparable, which responds to query methods.
I though that this kind of query concept was wrong, and was looking always for the command like concept. However it does make sense in situation like this where preparing is domain heavy concept which needs to be extracted from bike AMD put into a service. Then the dilemma is whether trip passes bikes and makes the service more context independent (he doesn't works with something that has bikes, he works with bikes directly). In this case the trip knows that are his bikes the thing that need Ti be prepare.
The other. Trip seems that. Still know that the bikes. Are prepare since still needs to respond tio bikes as a preparable.
But un tje example mechanic ask for the bikes,vehicles and something else from the trip so it totally make sense to pass the wrapping object trip.
Remove argument order dependency with a has table
Inheritance
Decoupling subclasses using hook messages (post_initialise)
It removes. The super from subclasses and therefore the knowledge within the subclass of the superclass
Query versus command important for testing
martes, 15 de septiembre de 2015
Test Equality
Entities can not be compared as value objects
IEqualityComparer use it to compare entities in tests:
Helper method that sets a value and return the entity itself with the same values. It helps to create expectations when only one property changes
Resemblance
Create subclass which implements equals
Likeness

