Index: src/webservice/tests/SetupTest.php
===================================================================
--- src/webservice/tests/SetupTest.php	(revision 02fbeb816a6fd00276fc6f4dfc1dd966ba3dc6d5)
+++ src/webservice/tests/SetupTest.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
@@ -19,4 +19,6 @@
 */
 
+require_once(__DIR__ ."/TestHelpers/TestSetup.php");
+
 class SetupTest extends PHPUnit_Framework_TestCase
 {
@@ -31,5 +33,5 @@
 
 		require_once($testconfig["webserviceDirectory"] ."/inc/envsetup.php");
-
+		
 		self::$_webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
 		self::assertNotNull(self::$_webserviceConfig);
@@ -38,4 +40,7 @@
 		self::assertInternaltype("string", self::$_dataDirectory);
 		self::assertTrue(!empty(self::$_dataDirectory));
+		if(file_exists(self::$_dataDirectory))
+			self::assertTrue(TestHelpers\TestSetup::wipeDataDirectory());
+
 		self::assertTrue(!file_exists(self::$_dataDirectory));
 	}
@@ -43,18 +48,6 @@
 	public static function tearDownAfterClass()
 	{
-		if(!file_exists(self::$_dataDirectory)){
-			return;
-		}
-		// clear data directory (not recursive, because there should be only a database file in it
-		$content = scandir(self::$_dataDirectory);
-		self::assertInternalType("array", $content);
-		foreach($content as $file){
-			if(!in_array($file, array(".",".."))){
-				self::assertTrue(unlink(self::$_dataDirectory ."/". $file));
-			}
-		}
-		
-		// remove datadirectory
-		self::assertTrue(rmdir(self::$_dataDirectory));
+		if(file_exists(self::$_dataDirectory))
+			self::assertTrue(TestHelpers\TestSetup::wipeDataDirectory());
 	}
 
@@ -163,9 +156,9 @@
 		$this->assertLessThan($versionSpatalite, 0, $prefix ." (Could not determine Spatalite version: ". $errorMessage .")");
 		$this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
-   }
+	}
    
-   protected static $_webserviceConfig;
-   protected static $_dataDirectory;
-   protected static $_testconfig;
+	protected static $_webserviceConfig;
+	protected static $_dataDirectory;
+	protected static $_testconfig;
 }
 ?>
Index: src/webservice/tests/StationsTest.php
===================================================================
--- src/webservice/tests/StationsTest.php	(revision 02fbeb816a6fd00276fc6f4dfc1dd966ba3dc6d5)
+++ src/webservice/tests/StationsTest.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
@@ -19,7 +19,6 @@
 */
 
-/**
-	* @todo Reset database before this test is run
-	*/
+require_once(__DIR__ ."/TestHelpers/TestSetup.php");
+
 class StationsTest extends PHPUnit_Framework_TestCase
 {
@@ -37,4 +36,16 @@
 		$this->_webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
 		$this->assertNotNull($this->_webserviceConfig);
+
+		$this->_dataDirectory = $this->_webserviceConfig->getConfig("dataDirectory");
+		$this->assertInternaltype("string", $this->_dataDirectory);
+		$this->assertTrue(!empty($this->_dataDirectory));
+		if(file_exists($this->_dataDirectory))
+			$this->assertTrue(TestHelpers\TestSetup::wipeDataDirectory());
+		$this->assertTrue(TestHelpers\TestSetup::databaseSetup());
+    }
+    
+    protected function tearDown(){
+		if(file_exists($this->_dataDirectory))
+			$this->assertTrue(TestHelpers\TestSetup::wipeDataDirectory());
     }
 
@@ -44,18 +55,14 @@
 
 		$this->assertInternalType("array", $stations);
+		$message = "";
+		if(array_key_exists("message", $stations))
+			$message = $stations["message"];
+		$this->assertTrue(!array_key_exists("result", $stations), $message);
 		$this->assertEquals(count($stations), 0);
 	}
-	
-	public function testStationRewrite()
-	{
-		$stations = $this->query("stations");
 
-		$this->assertInternalType("array", $stations);
-		$this->assertEquals(count($stations), 0);
-	}
-	
 	public function testRegisterStationUnprovenLocation()
 	{
-		$baseUrl = $this->_webserviceConfig->webserviceBaseUrl();
+		$baseUrl = TestHelpers\TestSetup::webserviceTestBaseUrl();
 		$this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl);
 		$this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl);
@@ -82,5 +89,5 @@
 	public function testRegisterStation()
 	{
-		$baseUrl = $this->_webserviceConfig->webserviceBaseUrl();
+		$baseUrl = TestHelpers\TestSetup::webserviceTestBaseUrl();
 		$this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl);
 		$this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl);
@@ -94,5 +101,4 @@
 		);
 
-		// sending must failing register request, caused by unproven location
 		$response = $client->post("index.php/stations/register",
 			[ "json" => ["name" => "My Weather Station", "city" => "Clausthal-Zellerfeld", "longitude" => 10.28152, "latitude" => 51.8281, "email" => "test@example.org"]]
@@ -113,5 +119,5 @@
 	
 	protected function query($url){
-		$baseUrl = $this->_webserviceConfig->webserviceBaseUrl();
+		$baseUrl = TestHelpers\TestSetup::webserviceTestBaseUrl();
 		$this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl);
 		$this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl);
@@ -138,4 +144,5 @@
 	protected $_testconfig;
 	protected $_webserviceConfig;
+	protected $_dataDirectory;
 }
 ?>
Index: src/webservice/tests/TestHelpers/TestSetup.php
===================================================================
--- src/webservice/tests/TestHelpers/TestSetup.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
+++ src/webservice/tests/TestHelpers/TestSetup.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
@@ -0,0 +1,133 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+namespace TestHelpers;
+
+class TestSetup {
+	
+	public static function webserviceTestBaseUrl(){
+		$file = __DIR__ ."/../testconfig/testconfig.php";
+		if(!file_exists($file)){
+			error_log("testconfig file ". $file ." not found");
+			return false;
+		}
+		require($file);
+		if(is_null($testconfig)){
+			error_log("No testconfig found");
+			return false;
+		}
+		require($testconfig["webserviceDirectory"] ."/inc/envsetup.php");
+		require_once($testconfig["webserviceDirectory"] ."/SiWeather/Webservice/WebserviceConfig.php");
+		
+		$webserviceConfig = new \SiWeather\Webservice\WebserviceConfig();
+		if(is_null($webserviceConfig)){
+			error_log("No webservice config created");
+			return false;
+		}
+		return "http://localhost:9999/". $webserviceConfig->getConfig("webserviceApiVersion") ."/";
+	}
+
+	/**
+	  * @brief Configures the database of the webservice which is used for the tests.
+	  *
+	  * @note This function checks whether the webservice base url starts with localhost. If not,
+	  *       false is returned and the remote webservice is not touched. We do not touch remote
+	  *       webservices, not on localhost for testing purposes.
+	  */
+	public static function databaseSetup(){
+		$file = __DIR__ ."/../testconfig/testconfig.php";
+		if(!file_exists($file)){
+			error_log("testconfig file ". $file ." not found");
+			return false;
+		}
+		require($file);
+		if(is_null($testconfig)){
+			error_log("No testconfig found");
+			return false;
+		}
+		
+		require($testconfig["webserviceDirectory"] ."/inc/envsetup.php");
+		require_once($testconfig["webserviceDirectory"] ."/SiWeather/Webservice/WebserviceConfig.php");
+		
+		$webserviceConfig = new \SiWeather\Webservice\WebserviceConfig();
+		if(is_null($webserviceConfig)){
+			error_log("No webservice config created");
+			return false;
+		}
+
+		$webserviceBaseUrl = self::webserviceTestBaseUrl();
+		if(empty($webserviceBaseUrl) || !preg_match("/^https?:\/\/localhost/", $webserviceBaseUrl)){
+			error_log("NOT TESTING AGAINST REMOTE WEBSERVICE. INSTALL WEBSERVICE ON LOCALHOST TO TEST IT!");
+			return false;
+		}
+		
+		$client = new \GuzzleHttp\Client
+		(
+			[
+				"base_uri" => $webserviceBaseUrl,
+				"timeout" => 5.0,
+				"http_errors" => false,
+			]
+		);
+		$response = $client->get("setup.php");
+		if($response->getStatusCode() !=  200){
+			error_log("Failed to setup webservice database: ". $response->getReasonPhrase());
+			return false;
+		}
+		$body = $response->getBody();
+		if(empty($body)){
+			error_log("Failed to setup webservice database: Empty response!");
+			return false;
+		}
+		
+		if(strpos($body, "error")){
+			error_log("Failed to setup webservice database: Found error in reply (". $body .")");
+			return false;
+		}
+
+		return true;
+	}
+
+	public static function wipeDataDirectory(){
+		$webserviceConfig = new \SiWeather\Webservice\WebserviceConfig();
+		$dataDirectory = $webserviceConfig->dataDirectory();
+		if(!file_exists($dataDirectory))
+			return true;
+
+		// clear data directory (not recursive, because there should be only a database file in it
+		$content = scandir($dataDirectory);
+		if(!is_array($content)){
+			error_log("result of scandir is not an array");
+			return false;
+		}
+		foreach($content as $file){
+			if(!in_array($file, array(".",".."))){
+				$file = $dataDirectory ."/". $file;
+				if(!unlink($file)){
+					error_log("Failed to delete file ". $file);
+					return false;
+				}
+			}
+		}
+		return rmdir($dataDirectory);
+	}
+}
+
+?>
Index: src/webservice/tests/bootstrap.php
===================================================================
--- src/webservice/tests/bootstrap.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
+++ src/webservice/tests/bootstrap.php	(revision d55ec21a7baa94629097e8a4e29c682e38829d3c)
@@ -0,0 +1,49 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+    
+    Followed the guide at http://tech.vg.no/2013/07/19/using-phps-built-in-web-server-in-your-test-suites/
+*/
+
+// Command that starts the built-in web server
+$command = sprintf(
+    'php -S %s:%d -t %s >/dev/null 2>&1 & echo $!',
+    WEB_SERVER_HOST,
+    WEB_SERVER_PORT,
+    WEB_SERVER_DOCROOT
+);
+ 
+// Execute the command and store the process ID
+$output = array(); 
+exec($command, $output);
+$pid = (int) $output[0];
+ 
+echo sprintf(
+    '%s - Web server started on %s:%d with PID %d', 
+    date('r'),
+    WEB_SERVER_HOST, 
+    WEB_SERVER_PORT, 
+    $pid
+) . PHP_EOL;
+ 
+// Kill the web server when the process ends
+register_shutdown_function(function() use ($pid) {
+    echo sprintf('%s - Killing process with ID %d', date('r'), $pid) . PHP_EOL;
+    exec('kill ' . $pid);
+});
+?>
