diff --git a/plugins/autotest/testrunner.cpp b/plugins/autotest/testrunner.cpp
index 50fbb053081cd931b4d2aa8b5c2dbf0271065ad1..25ea23f603392337d571ba2ea077ee70a15d3ab4 100644
--- a/plugins/autotest/testrunner.cpp
+++ b/plugins/autotest/testrunner.cpp
@@ -217,6 +217,13 @@ static void performTestRun(QFutureInterface<TestResult *> &futureInterface,
 
 void TestRunner::prepareToRunTests()
 {
+    ProjectExplorer::Internal::ProjectExplorerSettings projectExplorerSettings =
+        ProjectExplorer::ProjectExplorerPlugin::projectExplorerSettings();
+    if (projectExplorerSettings.buildBeforeDeploy && !projectExplorerSettings.saveBeforeBuild) {
+        if (!ProjectExplorer::ProjectExplorerPlugin::saveModifiedFiles())
+            return;
+    }
+
     const bool omitRunConfigWarnings = AutotestPlugin::instance()->settings()->omitRunConfigWarn;
 
     m_executingTests = true;
@@ -250,8 +257,6 @@ void TestRunner::prepareToRunTests()
         return;
     }
 
-    ProjectExplorer::Internal::ProjectExplorerSettings projectExplorerSettings =
-        ProjectExplorer::ProjectExplorerPlugin::projectExplorerSettings();
     if (!projectExplorerSettings.buildBeforeDeploy) {
         runTests();
     } else {