ASP.NET - Generic InMemoryCache helper
Nice code - Usage of fluent interfaces - Java code
Seen in a test that searches for products
aProduct(“LAB-1234”)
.named(“Labrador Retriever”)
aProduct(“CHE-5678”)
.named(“Chesapeake”)
.describedAs(“Chesapeake bay retriever”)
aProduct()
.named(“Dalmatian”)
Creates 3 products with the specified features.
The whole test looks like this
@Test public void
searchesAndFindsProductsInCatalog() {
context.given(aProduct(“LAB-1234”).named(“Labrador Retriever”),
aProduct(“CHE-5678”).named(“Chesapeake”).describedAs(“Chesapeake bay retriever”),
aProduct().named(“Dalmatian”));
petstore.searchFor(“retriever”);
petstore.displaysNumberOfResults(2);
petstore.displaysProduct(“LAB-1234”, “Labrador Retriever”);
petstore.displaysProduct(“CHE-5678”, “Chesapeake”);
}
Read all the code here
https://github.com/testinfected/petstore/blob/master/petstore-system-tests/src/test/java/test/system/com/pyxis/petstore/SearchFeature.java
Test names can have whitespace #fsharp
How awesome is that!
open NUnit.Framework
let [] ``This is a test with some whitespace`` () = Assert.IsTrue(true)
Tests are not DRY
public class TennisGameSpecs
{
[TestFixture]
public class GetScores
{
[Test]
public void NewGame_Player1_ShouldReturn0()
{
TennisGame tennisGame = new TennisGame(); // = "NewGame"
Assert.That(tennisGame.Player1.Score, Is.EqualTo(0));
}
}
Test Names and the actual tests contain duplication.
In the example above “NewGame” in the name of the test and the actual code…
I think that is the reason why we had a discussion about Naming Tests
XUnit wins over MSTest, expecting an exception
// XUnit
[Fact]
public void ThrowsException__PassingNegativeValues()
{
Assert.Throws<ArgumentException>(() => sut.Add("-1"));
}
// MSTest
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void ThrowsException__PassingNegativeValues_()
{
sut.Add("-1");
}
Do you use microtypes / explicit types? via @NotMyself
Microtypes to improve readability and avoid errors
I haven’t used Microtypes myself, but I can certainly see the advantage of those. Especially after Refactoring and moving more functionality to those types…
Passing Strings and doubles around in an application can significantly increase the likelihood of inadvertantly passing incorrect parameters to methods. By strongly typing all string and number parameter types, this can be simply avoided. Its then also possible to add behaviour to these types, meaning that “utility” classes are removed, keeping behaviour close to the objects that need it.
http://www.time4tea.net/wiki/display/MAIN/Microtypes
I had Sonar on my “things to look into” list for a while. And this feature makes it even more interesting.
What is Sonar?
Sonar is an open platform to manage code quality. As such, it covers the 7 axes of code quality:
- Architecture & Design
- Comments
- Duplications
- Coding rules
- Potential bugs
- Complexity
- Unit tests
from http://www.sonarsource.org/
Aligns quite nicely with the 4 rules of simple design
A cool library that Llewellyn Falco and Dan Gilkerson put together.
I was skeptical about this library when I heard about it in the podcast, but now I like the idea. Especially for regression testing of external APIs. For writing your tests first TDD style it might not make sense ;-)
CopyCat is born.
CopyCat checks if your text is original and detects duplicates!
http://copycat.apphb.com/
CopyCat is a private pet project of mine, that I started to develop one month ago.
I always wanted to use all those nice shiny toys and techniques like: AppHarbour, Git, Continuous Deployment, NoSQL databases, MVC3, Cassette … and TDD, BDD approach on a green field…
So I started my own project with all those!
Bigger blog post on my blog coming soon…
A couple of nice features in this base class for viewmodels:
- Strongly typed Property notification for databinding
- Automatic Method Execution
Code samples for #1
public string Text
{
get { return Get(() => Text); }
set { Set(() => Text, value); }
}
Code samples for #2
public double Score
{
get { return Get(() => Score); }
set { Set(() => Score, value); }
}
[DependsUpon("Score")]
public void WhenScoreChanges()
{
// Handle this case
}