diff --git a/src/plugins/cpptools/cppheadersource_test.cpp b/src/plugins/cpptools/cppheadersource_test.cpp
index bbc4efa24ffabe161db5af9b3eb2c6a5a1821370..c047d0fe43ab4b732707f7e83009241c42637d03 100644
--- a/src/plugins/cpptools/cppheadersource_test.cpp
+++ b/src/plugins/cpptools/cppheadersource_test.cpp
@@ -30,13 +30,26 @@
 #include "cpptoolsplugin.h"
 #include "cpptoolsreuse.h"
 
-#include <coreplugin/testdatadir.h>
+#include <utils/fileutils.h>
 
 #include <QDir>
 #include <QtTest>
 
 static inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }
 
+static void createTempFile(const QString &fileName)
+{
+    QFile file(fileName);
+    QDir(QFileInfo(fileName).absolutePath()).mkpath(_("."));
+    file.open(QFile::WriteOnly);
+    file.close();
+}
+
+static QString baseTestDir()
+{
+    return QDir::tempPath() + _("/qtc_cppheadersource/");
+}
+
 namespace CppTools {
 namespace Internal {
 
@@ -46,11 +59,13 @@ void CppToolsPlugin::test_headersource()
     QFETCH(QString, headerFileName);
 
     bool wasHeader;
-    Core::Tests::TestDataDir dataDir(_(SRCDIR "/../../../tests/cppheadersource/")
-        + _(QTest::currentDataTag()));
+    const QString baseDir = baseTestDir();
+    QDir path = QDir(baseDir + _(QTest::currentDataTag()));
 
-    const QString sourcePath = dataDir.file(sourceFileName);
-    const QString headerPath = dataDir.file(headerFileName);
+    const QString sourcePath = path.absoluteFilePath(sourceFileName);
+    const QString headerPath = path.absoluteFilePath(headerFileName);
+    createTempFile(sourcePath);
+    createTempFile(headerPath);
 
     clearHeaderSourceCache();
     QCOMPARE(correspondingHeaderOrSource(sourcePath, &wasHeader), headerPath);
@@ -68,5 +83,15 @@ void CppToolsPlugin::test_headersource_data()
     QTest::newRow("includesub") << _("foo.cpp") << _("include/foo.h");
 }
 
+void CppToolsPlugin::initTestCase()
+{
+    QDir(baseTestDir()).mkpath(_("."));
+}
+
+void CppToolsPlugin::cleanupTestCase()
+{
+    Utils::FileUtils::removeRecursively(Utils::FileName::fromString(baseTestDir()));
+}
+
 } // namespace Internal
 } // namespace CppTools
diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h
index c5d573e1cb99189260ae1844f80b42f96e1377aa..d99fcb738b7e7e69ebaef28d17693eee8629b52c 100644
--- a/src/plugins/cpptools/cpptoolsplugin.h
+++ b/src/plugins/cpptools/cpptoolsplugin.h
@@ -77,6 +77,10 @@ public slots:
 
 private slots:
 #ifdef WITH_TESTS
+    // Init/Cleanup methods implemented in cppheadersource_test.cpp
+    void initTestCase();
+    void cleanupTestCase();
+
     void test_codegen_public_in_empty_class();
     void test_codegen_public_in_nonempty_class();
     void test_codegen_public_before_protected();
diff --git a/tests/cppheadersource/includesub/foo.cpp b/tests/cppheadersource/includesub/foo.cpp
deleted file mode 100644
index e8e1f1fa29f29c028fa08820d648bb10a0a51ec9..0000000000000000000000000000000000000000
--- a/tests/cppheadersource/includesub/foo.cpp
+++ /dev/null
@@ -1 +0,0 @@
-// Comment
diff --git a/tests/cppheadersource/includesub/include/foo.h b/tests/cppheadersource/includesub/include/foo.h
deleted file mode 100644
index e8e1f1fa29f29c028fa08820d648bb10a0a51ec9..0000000000000000000000000000000000000000
--- a/tests/cppheadersource/includesub/include/foo.h
+++ /dev/null
@@ -1 +0,0 @@
-// Comment
diff --git a/tests/cppheadersource/samedir/foo.cpp b/tests/cppheadersource/samedir/foo.cpp
deleted file mode 100644
index e8e1f1fa29f29c028fa08820d648bb10a0a51ec9..0000000000000000000000000000000000000000
--- a/tests/cppheadersource/samedir/foo.cpp
+++ /dev/null
@@ -1 +0,0 @@
-// Comment
diff --git a/tests/cppheadersource/samedir/foo.h b/tests/cppheadersource/samedir/foo.h
deleted file mode 100644
index e8e1f1fa29f29c028fa08820d648bb10a0a51ec9..0000000000000000000000000000000000000000
--- a/tests/cppheadersource/samedir/foo.h
+++ /dev/null
@@ -1 +0,0 @@
-// Comment