Wanneer je start met unit testing, zijn er diverse handvaten die je kunt gebruiken om unit testing te gebruiken in je applicaties.
In de test logica mag je geen gebruik maken van
- IFs statements
- Switch of case statements
- Vervolgens moet de test code die je opstelt herhaalbaar uitgevoerd kunnen worden.
- Vermijd Multiple Asserts.
- Integration test en een unit test moet je scheiden
Alle testen in de solution runnen, wanneer een test failed dan is er een probleem. Dus -> betere test
-> integration test
-> er is geen configuratie maar je moet de test vertrouwen
Een verschil tussen een unit test en integration test is dat bij een integration test configuration noodzakelijk is. (gebruik de postfix unittest en integrationtest voor de desbetreffende testen)
Bij 'gewone' code geldt al gebruik GEEN magic numbers, en dit gaat ook op voor test code.
Syntax method names (bij testen
- method name
-state undertest
- expected behavior
-> dat leidt tot 'Add_LessThanZero_ThrowException'.
Helper methods
- '_make' -> create
- '_change' -> update
- '_assert_'
- Alleen public testen. DIt is een contract naar buiten toe. Private/protected is voor intern gebruik en meer verandelijk.
- Incremental work! (stapje voor stapje)
- [setup] attribut, dit is uitgevoerd voor ELKE test
- start een fail test, de test mag niet blijven 'falen' als de productie code is aangepast
- TDD -> vind de bugs sneller
- Simple code kan bugs bevatten
- Test names zijn lang maar dit is readabily (documentatie)
- Duplicated de logic in de test is een probleem, je test de logica niet. Het eindresultaat is niet gecontroleerd de bug wordt gewoon opnieuw gecreereerd in de Assert.AreEqual. Unittest mag geen logica bevatten, zelfs geen string.Format etc.
- Verander nooit een test. Als een test niet goed is (failuing test). Tegenstrijdige requirements vraag na welke requirement geldig is.
- Code coverage
Tuesday, December 29, 2009
Unit testing losse flarden
Saturday, November 7, 2009
SQL datetime headaches
Usefull page for that
But it did not realy have what i wanted from it.
So the final solution was the following
to get a format like this:
2008-11-13 17:29:00
SET generated = cast( getdate() - 8 as smalldatetime)
WCF service error contract name not found
solution on the blog of Peter Morris:
The contract name xxxxxxx could not be found in the list of contracts implemented by the service
So what you need to do:
Check names of interfaces
Check namespaces
Check the service attributes ([AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)])
What is Inversion of control and Dependency injection
And we where using some of the terms often related to this topic and it was confusing me. I decided to get my facts straight.
the principle comes down to the following:
A Control gets all his data and events from the outside and itself does not know anything about the context it is being used in. This results in lousely coupled Code/controls which in turn should make them more reusable.
http://www.codeproject.com/KB/aspnet/IOCDI.aspx
Conlusion
Inversion of control is a principle with the goal to help you create better, more reusable code
Dependency injection is a specific method of achieving inversion of control.(Unity is a method for dependency injection)
Path resolution through IUrlResolutionService
When working on a project at work i saw a colleage use the following interface
IUrlResolutionService
I had never seen that one before and i looked it up
MSDN page
Quote from the page:
Defines a service implemented by objects to resolve relative URLs based on contextual information.
....
This interface defines the service that is used to resolve URL paths. The IUrlResolutionService interface is used for resolving relative paths and paths that contain the ~ operator. Server controls that reference resources can define the paths to the resources through the ~ operator, which represents the root of the current application. A path containing the ~ operator will not work if passed to the browser. The server control must convert the path to an absolute or relative path before passing it to the browser.
Control implements this interface. A control that derives from Control could override this implementation to provide customized resolution of URLs.
you can pass along controls or the page deeper into your code using this interface to resolve app relative paths for you. For example "~/foo/bar.aspx" would get resolved properly by the control to a path the client can use based on the current context of the control/page.
I myself are using this more often these days it seems a nice way to do it.
Steps until failure
on Found on the website:
http://odetocode.com/Blogs/scott/default.aspx
void Process(){
Func<bool>[] steps = {
Step1,
Step2,
Step3,
Step4,
Step5
};
}
void ExecuteStepsUntilFirstFailure(IEnumerable<Func<bool>> steps)
{
steps.All(step => step() == true);
} The All operator is documented as stopping as soon as a result can be determined, so the above code is equivalent to the following:
void ExecuteStepsUntilFirstFailure(IEnumerable<Func<bool>> steps)
{
foreach (var step in steps)
{
if (step() == false)
{
break;
}
}
}
Thursday, October 29, 2009
Environment.NewLine
When you create a string with must have multiple line use the option Environment.NewLine and not the escape characters.
see