Skip to content

Unit tests quickstart

24-Jun-08

A friend asked me, so I conclude someone might need a jumpstart on unit tests.

Here’s a short list of short (though very deep, if not best) intros.

For deeper dive, take a “xUnit patterns” book (this one is longer).

For Kent Beck’s book on TDD, shame on me - I never read it. Though after “XP explained” I don’t strive for reading his books.

// If you’re interested in XP and “XP explained” criticism, take a look at “Extreme Programming Considered Harmful for Reliable Software Development” by Gerald Keefer.

Please bookmark this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • Live
  • Google
  • description
  • YahooMyWeb
  • Technorati

On unit tests in Visual Studio 2008 vs NUnit

02-Jun-08

My not-so-humble evaluation of VS tests distinctions from NUnit is (in points on -10 to 10 scale).

  • (-4) To run tests, VS launches an entire process which takes no less then 3 seconds to start. If you’re in “F5 hit breakpoint - Shift-F5″ loop, that’s disgusting. NUnit tests can be run in-process by Resharper or TestDriver.NET;
  • (-2) GUI that shows where test failed is ugly. You don’t get to failed line on double-click, you first get to test log page. Status and call stack are necessary, but I’d like not to trash my document tabs, I already have enough of them open. You can’t make that kind of windows docked/floating;
  • (-1) You got a “public TestContext TestContext;” sticking in your code. You’ll need it only when it comes to testing on data, which doesn’t always happen, even in a data-driven application;
  • (-1) It’s a “not invented here” technology, while NUnit was around for years;

Edit: In a moment of madness, I mixed together coverage profiling and unit testing tools. May God and readers forgive my aberration.

Edit2: If you need a half-page kickstart in unit testing techniques, the next post can help.

Please bookmark this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • Live
  • Google
  • description
  • YahooMyWeb
  • Technorati

Please meet: Lua

15-May-08

Lua recently became very popular. I encountered Lua scripting in several applications including popular games, I believe it’s used in even more then Wikipedia says.

It’s extremely simple:

  • 6 data types (that’s counting “nul” and “function”),
  • no C++-style OOP out-of-box (but you can program one, he-he),
  • 400K of pure-C code

but is loaded with in-fashion features like

The only metaprogramming tutorial (with a ready code to implement virtual methods) is “Programming in Lua” book. Still, I don’t see a code to implement ad-hoc polymorphism… Maybe it’s a reason for another post :)

Redistributed book removed: it violated copyright.

Please bookmark this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • Live
  • Google
  • description
  • YahooMyWeb
  • Technorati

Another C++ quiz, simpler

14-May-08

Did you ever think, what happens if you take a member pointer to a virtual function of a class, and then call it on another instance of derived class (that overrides that member)?

What if you do the same for nonvirtual function?

Here’s a test:

#include <iostream>

class A
{
  public:
  virtual void f() { std::cout << “A::f()\n”; };
  void g() { std::cout << “A::g()\n”; };
};

class B : public A
{
  public:
  virtual void f() { std::cout << “B::f()\n”; };
  void g() { std::cout << “B::g()\n”; };
};

typedef void (A::*VirtualFunctionPointer) ();

int main()
{
  A a;
  B b;
  B* pb = &b;

  VirtualFunctionPointer p = &A::f;
  (pb->*p) ();

  p = &A::g;
  (pb->*p) ();
  return 0;
}

Answer is in comments.

Please bookmark this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • Live
  • Google
  • description
  • YahooMyWeb
  • Technorati

C++ quiz from the past

14-May-08

One of my friends once encountered a C++ compilation issue.
A program is given:

#include <iostream>
#include <sstream>
using namespace std;

#define SFORMAT(e) ((dynamic_cast<const ostringstream&>(ostringstream() << e)).str())

int main(int argc, char* argv[])
{
cout << SFORMAT(“2 x “ << ” 2 = “ << 2*2);
return 0;
}

No one asks you what it will print, unless you’re a god.

Question is: why is the first const char* printed as a pointer, instead of what we need?
Two years ago, I couldn’t tell.
Some guru from Apple answered this in a newsgroup.

Here, take another, simpler C++ quiz about member pointers.

Please bookmark this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • Live
  • Google
  • description
  • YahooMyWeb
  • Technorati

Here comes INTSPEI P-Navigator

15-Apr-08

We're living in Yellow Submarine... So here’s first beta version of our product: P-Navigator, our Yellow Submarine.

What does it do? Mostly it’s a front-end to web search service, plus some more tasties.

Why desktop client? For every search, it does several searches at once. This should save time.

Here are screenshots, here’s a 7M Flash video.

If WebFerret has 10M downloads, why can’t we have some?

Lot of things are done, even more are due to do. Like speed it up, add Wikipedia search, getting page tags from social networks, page clustering and graphical maps, etc etc etc.

Let’s see how it goes…

Please bookmark this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • Live
  • Google
  • description
  • YahooMyWeb
  • Technorati

MSBuild don’ts

15-Apr-08

A couple of notes how NOT to use MSBuild.

  1. Don’t generate files with AssemblyInfo task. It screws comments, screws InternalsVisibleTo attributes, and whatever else it doesn’t account for.
    Instead
    : Use
    <FileUpdate Files="@(AssemblyInfoFiles)"
    Regex="AssemblyVersion\(".*?"\)\]"
    ReplacementText="AssemblyVersion("$(Major).$(Minor).$(Build).$(Revision)")]"
    />
    <FileUpdate Files="@(AssemblyInfoFiles)"
    Regex="AssemblyFileVersion\(".*?"\)\]"
    ReplacementText="AssemblyFileVersion("$(Major).$(Minor).$(Build).$(Revision)")]"
    />
  2. Don’t account for TfsXXXX community tasks - it won’t run on VS 2008 with Team Explorer 9.0.
    Instead:  Use <Exec Command=”tf …”>.
    And if you have domain authentication in TFS and don’t run integration under domain user (which happens), you even can’t run tf in cmd-line mode: stupid authentication dialog will pop up.
  3. Do not use local files to store version number. You will lose them when moving build to another host, so use only source control-dependent files.
    Might seem evident, but strange how many people miss this.
    So you’ll need to
    <Attrib Files="version.txt" Normal="true" />
  4. Per Scott Colestock’s post, “since TfsVersion interrogates the build server’s workspace, and BuildNumberOverrideTarget comes early in the process… you might find that you don’t get the changeset number you expect”.
  5. Don’t try to operate on XML node collections with tasks other then Xslt.
    For instance, XmlRead returns a Nodeset only as a string of “;”-joined
    Node.Value-s.
    XmlQuery supports Values property, though I wasn’t able to operate it’s results.
    Instead you can use ReadLinesFromFile (sadly, this will trim the lines).
    My personal choice for not-too-complex XML is… you can guess… yes, FileUpdate.
  6. Don’t use FtpUpload. It won’t create folders for you.
    Just <Exec> a ftp…
    By the way, Windows’ ftp.exe client is unable to upload in passive mode. You can download passively, if you issue “LITERAL PASV“, but it won’t help the client.
Please bookmark this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • Live
  • Google
  • description
  • YahooMyWeb
  • Technorati

Bootstrapper also can’t install your application after rebooting…

04-Apr-08

Another problem with MSBuild bootstrappers that can screw all your installation

If scheduling reboot after installing .NET or other prerequisites, bootstrapper copies itself to run from TEMP on boot. Why not staying where it is - who knows. And definitely, all the other MSIs are not copied, so it won’t find them. Reproduced for me.

Now give up and go write own bootstrapper. I’m setiously considering going for InnoSetup deployment.

For now, I’m trying a crazy ting, to copy MSI to TEMP for Setup.exe to find it after reincarnation… It’s the way to use given tools.

Please bookmark this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • Live
  • Google
  • description
  • YahooMyWeb
  • Technorati

Can’t run .NET bootstrapper from an MSI

02-Apr-08

Now I know it.

It’s Windows Installer error 1618 that I didn’t see somewhy when attempting to fix .NET bootstrapper. Either I was inattentive or it wasn’t there: “Another copy of msiexec is running”. You can’t have two Windows Installers running, at least if one of them installs .NET. Information is from this maillist post.

Why? Implementation limitations, I believe. No sane reasons for such a contract, no article mentioned this. Surely, who’s going to declare own “features” of that kind - just a gentle hints that “you should better use bootstrapper”. Another reason to long for a systems where setup is just a copy.

So go pack a MSI, then make a MSBuild bootstrapper.

Oh wait, do I have to have 2 files in my installation? And my customers can’t download one file?

Yes. Or go for WinZip Self-Extractor, or WinRar, or whatever else.

What about build scripts? For WinRar, here’s a nice sample. For WinZip sfx, there’s also a command-line interface. Do a

wzipse32 %ARC_NAME% -setup -auto -runasuser -le -i ../icon.ico -wait msiexec -c ".\setup.exe"

WinZip will do the thing, though displaying some dialogs we don’t need at all.

Oh, WinRar won’t work, because it erases temporary files upon setup.exe completion. And we need to wait for msiexec, because setup.exe exits earlier. What a pity.

Please bookmark this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • Live
  • Google
  • description
  • YahooMyWeb
  • Technorati

MSBuild bootstrapper for .NET 3.0 broken?

31-Mar-08

After Microsoft didn’t include .NET 3.5 in any current release of Windows (read “Vista service pack 1″), some of us developers who believed in long-ago C# 3.0 ads, had to roll back to .NET 3.0 and C# 2.0.

Including me.

Not mentioning pain of rolling back all LINQ tasties in code and debugging our replacements (do you know why you can’t implement Where() just with yield-style function?), it means installing .NET 3.0.

It seemed to be not a problem, having a MSBuild code snippet that worked for 3.5 - just replace 3.5 with 3.0:

<ItemGroup>
<BootstrapperFile Include="Microsoft.Net.Framework.3.0">
<ProductName>.NET Framework 3.0</ProductName>
</BootstrapperFile>
<BootstrapperFile Include="Microsoft.Windows.Installer.3.1">
<ProductName>Windows Installer 3.1</ProductName>
</BootstrapperFile>

<Target Name="Bootstrapper">
<GenerateBootstrapper
ApplicationName="blah blah blah blah"
BootstrapperItems="@(BootstrapperFile)"
BootstrapperKeyFile=""
OutputPath="obj"
ComponentsLocation="HomeSite" CopyComponents="false"
SupportUrl="http://www.microsoft.com/downloads/details.aspx?familyid=10CC340B-F857-4A14-83F5-25634C3BF043"
Culture="en" Path="$(BootstrapperPath)"/>
</Target>

Won’t work.

Hell why? Who knows. Logs in temp don’t give proper diagnostics, nor system events do. WPF fails to install at some point onto every XP installations we have, including clean special test XP SP2 VMWare images downloaded from Microsoft.

Update: Here’s the answer.

Now I rolled back to dotnetfx3setup.exe redistributable. It’s 2.8M compared to 300K bootstrapper generated by MSBuild, and it’s a pain to see installer grow…And if .NET 3.0 is already installed it starts to uninstall it… and there is no key to make it just “check or install”, need to trick it via WiX.

But we have to pay it. Oh my.

All over the Web I see no evidence that any man walked this path before. For.NET 2.0 - a lot of mentions and code samples. And completely empty for .NET 3.0.

Please bookmark this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • Live
  • Google
  • description
  • YahooMyWeb
  • Technorati

C++ static code checker

26-Mar-08

Did you ever try parsing C++? What about parsing for every combination of possible define-s at once?

Microsoft has a static code checker tools for C++, like FxCop for .NET.

That’s awfully complex task, you now see. In .NET you can analyze bytecode, and luckily don’t really need to account for conditional compilation. In C++ where everthing is about #ifdef - it’s hell.

I never heared of anything like that. Though Insure++ or AQTime do way more things when profiling runtime, they of course find only things that were on necessary execution paths.

Please bookmark this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • Live
  • Google
  • description
  • YahooMyWeb
  • Technorati

WiX linkdump: samples and howto-s I found, mostly .NET deployment

21-Mar-08

Some pages that somewhy didn’t appear at top of Google searches for WiX help.

Please bookmark this post: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • StumbleUpon
  • Live
  • Google
  • description
  • YahooMyWeb
  • Technorati