Showing posts with label testing. Show all posts
Showing posts with label testing. Show all posts

Saturday, February 12, 2011

Ignoring JUnit tests at runtime

Sometimes I want to ignore particular test failures. In fact I don't want the tests to run at all because I know they will fail. Not that they are broken, but because they depend on part of the infrastructure that isn't available right now.

E.g. in the web-validators project, I wanted to have the ability to ignore the integration tests (which test remote validation services integration) when the remote sites aren't reachable.

I could also have used Assume, but somewhat I am not completely satisfied with that solution. The Assume calls go in the test code and

  • can't be used at a class level

  • aren't as good from a self-documenting perspective

  • don't have access to method information, e.g. other annotations

  • will execute my test code anyway, which can cause slow-downs, etc (time outs generally take a bit of time to trigger)



I could also have grouped my network dependent tests in a special suite or using a Category, but then I have to enable or disable it myself (i.e. make suites that match my grouping).

I prefer tests that enable themselves automatically.

So I came up with this solution: I have created a new Runner, and a new version of the Ignore annotation called RuntimeIgnore to which I specify optional extra argument(s): the name of a class to instantiate and execute to check whether an ignore condition is satisfied.

The disadvantage of the current patch is that I still have to have my own Runner. I don't like that too much (because to combine multiple enhancements you might have to combine runners) so I submitted an enhancement to JUnit as I merged that approach into the existing JUnit 4 Runner and @Ignore annotation.
Note: the patch isn't fully complete (cleanups, documentation left aside), it's more like a RFC. Feel free to comment.

How could you use this ? Instead of doing something like:


@Category("LinuxIT")
@Test thisTestShouldOnlyRunOnLinux() {
// my test code
}


and then enable your group of tests using Suites.

or

@Test thisTestShouldOnlyRunOnLinux() {
if (notOnLinux()) {
// my test code
}
}


You can do:


@Ignore(ifTrue=NotOnLinux.class)
@Test thisTestShouldOnlyRunOnLinux() {
// my test code
}


The same apply to classes, e.g.


@Ignore(if=NotOnLinux.class)
class MyLinuxTests {
@Test ...
@Test ...
}

You can also take advantage of DRY principles on Convention over Configuration doing


@Ignore(ifTrue=TestNameDoesntMatchPlatform.class)
@Test onLinux_aTest() {
// my test code for Linux
}

@Ignore(ifTrue=TestNameDoesntMatchPlatform.class)
@Test onWindows_aTest() {
// my test code for Windows
}


( in case you haven't followed the above code will not run in code taken from the JUnit official repository ! )

Update 1: after a comment from a JUnit commiter on my pull request/RFC, I made a slightly different version of the patch that doesn't require any change made to JUnit. By using MethodRules intead of a custom Runner, I am achieving almost the same thing. See the change here.

Wednesday, January 5, 2011

yui-runner, what it's for ?

I've released the first public version of yui-runner, a small framework for automating the running of YUI javascript unit tests and reporting of their results.

See https://github.com/lacostej/yui-runner

As the main goal is to be able to run your tests from anywhere, the integration is done thanks to a JUnit runner. This means your tests will run in maven thanks to surefire or in your favorite editor.

An example project can be found under https://github.com/lacostej/yui-runner/tree/master/yui-runner-it/src/test/resources.

The project will soon be available on ibiblio, something I'll blog about.

Note: the API for yui-runner is going to change for more flexibility in selecting the URLs to load.

Wednesday, August 25, 2010

Minimalist groovy BDD framework, from executable documentation to readable tests

In many projects, my target customers are other developers, not an end user that write prose. I am a developer. I don't write documentation, I write code, documented code.

When it comes to testing, I like the BDD approach. I've tested various BDD frameworks (easyb, cucumber, spock...). But I wasn't completely satisfied for various reasons (setup complexity, issues, maintainability, toolchain).

So I've gone back from executable documentation to readable tests. And I have settled on my own framework. Framework is a big name, you will see. In combination with mockito and a few coding conventions, it's the 1% that give me the 99% that I am looking for.

Thursday, October 15, 2009

Split testing

Found this little django framework to implement split testing. Nice. Do you do split testing ?

Some links. A 1h video from Google (too long, I want the slides), a nice s5 presentation.


Updates:

Friday, October 9, 2009

[ANNOUNCE] nosyd 0.0.5

Changes since last announced version:


0.0.5 (2009-10-09)
==================

- Nosyd should now run on Mac OS X
- Mac OS X / Growl notifier support (http://growl.info/)
- new Django builder
- new CLI options (--stop)
- be smarter at identifying the monitored project files
- some performance improvements (cache some of the monitored files resolution to lower CPU usage)
- auto-rebuild project when .nosy file is changed

0.0.4 (2009-10-06)
==================

- setuptools support. Project split into multiple files


pynotify support

Growl support

More info here. Code still on github.

(Thanks to Sergio for testing on Mac OX X)

Saturday, September 26, 2009

[ANNOUNCE] nosyd 0.0.3

Some more features since 0.0.1:

  • support of maven2/surefire builds and (untested) trial
  • new command line features: --clean
  • auto-reload of nosyd and project configurations
  • configuration for nosyd
  • try to be more cross platform (untested)


Friday, September 25, 2009

CITConf Paris followup

I was supposed to attend CITConf last week-end, but some real-life virus forced me to cancel my trip. The same virus that kept me in bed most of the week. #&#"(¤/"

There have been interesting discussions on the mailing list:

Thursday, September 24, 2009

Lightweight personal continous integration

Getting timely feedback is the key to improved software development productivity and software quality. That's why we have automated testing and CI servers.

Running a full CI server on your machine is a solution I've used in the past for some middle size projects. Using a personnal branch on a distributed SCM is another solution for complex projects / long running branches.

For simple projects, you can easily run a basic CI-like system on your machine. I call this lightweight personal CI.

Jeff Winkler's original nosy script is a great reminder that software should be kept simple and right to the point.

See also Doug Latornell's version




Here's my humble version, with a couple of extra features, in particular Gnome notifications and parsing of the XUnit like XML result.

Too bad I am hitting a lib notify Markup notification issue on Ubuntu 9.04, I can't display pretty HTML. On an unrelated note, launchpad 3.0 launched yesterday.

Building python projects on eapps.com

Eapps.com VPS currently use CentOs 5.2 and python 2.4. Here's my worklog for getting python2.6 projects to build with nose on my hudson server hosted by eapps.com.

Here's the result:




Thursday, September 17, 2009

nose, subversion and executable bits

For some reason, nose wasn't executing some of my tests. I found out that nose doesn't select test files if they have an executable bit, and that subversion was configured to create the files with the executable bit. That's a bit unfortunate as I want some python files to be executable, other not. I guess I will let them non executable by default. Worklog below