diff --git a/Setup.lhs b/Setup.lhs
--- a/Setup.lhs
+++ b/Setup.lhs
@@ -6,16 +6,26 @@
 > import Distribution.Simple.Utils ( rawSystemExit )
 > import Distribution.Verbosity ( normal )
 > import System.FilePath ( (</>) )
-
-> main = defaultMainWithHooks hooks
+> import Control.Monad ( forM_, when )
+> import Data.Char ( toLower )
 
-> hooks = simpleUserHooks { instHook = inst
->                         , runTests = test
->                         }
+> main = defaultMainWithHooks $ handleTestExes simpleUserHooks
 
-> inst pkg = instHook simpleUserHooks $ pkg { executables = [] }
+> handleTestExes hooks = hooks { instHook = dropTestExes instHook
+>                              , copyHook = dropTestExes copyHook
+>                              , runTests = runTestExes
+>                              }
+>     where
+>       dropTestExes hook pkg =
+>           let nonTest = filter (not . isTestExe) (executables pkg)
+>           in hook hooks $ pkg { executables = nonTest }
+>
+>       runTestExes args _unknown pkg lbi = do
+>         buildHook hooks pkg lbi hooks defaultBuildFlags
+>         forM_ (executables pkg) $ \exe ->
+>             let testPath = buildDir lbi </> exeName exe </> exeName exe
+>             in when (isTestExe exe) $ rawSystemExit normal testPath args
 
-> test args _unknown pkg lbi = do
->   buildHook hooks pkg lbi hooks defaultBuildFlags
->   let testPath = buildDir lbi </> "test" </> "test"
->   rawSystemExit normal testPath args
+> isTestExe exe =
+>     let fields = customFieldsBI (buildInfo exe)
+>     in ["true"] == [ map toLower val | ("x-test-executable", val) <- fields ]
diff --git a/urlencoded.cabal b/urlencoded.cabal
--- a/urlencoded.cabal
+++ b/urlencoded.cabal
@@ -1,6 +1,6 @@
 name:                urlencoded
 Cabal-Version:       >= 1.6
-version:             0.1
+version:             0.1.0.1
 synopsis:            Generate or process x-www-urlencoded data
 
 description:         Generate or process x-www-urlencoded data as it
@@ -33,3 +33,4 @@
   GHC-Options: -Wall
   Main-is: TestDriver.hs
   HS-Source-Dirs: src, test
+  X-Test-Executable: true
