diff --git a/src/Tests/EncryptTest.php b/src/Tests/EncryptTest.php
index 4d17b84..abd663c 100644
--- a/src/Tests/EncryptTest.php
+++ b/src/Tests/EncryptTest.php
@@ -2,109 +2,17 @@
 
 /**
  * @file
- * Contains Drupal\encrypt\Tests\EncryptServiceTest.
+ * Contains \Drupal\encrypt\Tests\EncryptTest.
  */
 
 namespace Drupal\encrypt\Tests;
 
-use Drupal\simpletest\WebTestBase;
-
 /**
  * Tests the encrypt admin UI and encryption / decryption service.
  *
  * @group encrypt
  */
-class EncryptTest extends WebTestBase {
-
-  /**
-   * Modules to enable for this test.
-   *
-   * @var string[]
-   */
-  public static $modules = array('key', 'encrypt', 'encrypt_test');
-
-  /**
-   * An administrator user.
-   *
-   * @var \Drupal\user\Entity\User
-   */
-  protected $adminUser;
-
-
-  /**
-   * A list of testkeys.
-   *
-   * @var \Drupal\key\Entity\Key[]
-   */
-  protected $testKeys;
-
-  /**
-   * {@inheritdoc}
-   */
-  protected function setUp() {
-    parent::setUp();
-
-    $this->adminUser = $this->drupalCreateUser([
-      'access administration pages',
-      'administer encrypt',
-      'administer keys',
-    ]);
-    $this->drupalLogin($this->adminUser);
-    $this->createTestKeys();
-  }
-
-  /**
-   * Creates a test key for usage in the tests.
-   */
-  protected function createTestKeys() {
-    // Create a 128bit testkey.
-    $this->drupalGet('admin/config/system/keys/add');
-    $edit = [
-      'key_type' => 'encryption',
-    ];
-    $this->drupalPostAjaxForm(NULL, $edit, 'key_type');
-    $edit = [
-      'key_provider' => 'config',
-    ];
-    $this->drupalPostAjaxForm(NULL, $edit, 'key_provider');
-
-    $edit = [
-      'id' => 'testing_key_128',
-      'label' => 'Testing Key 128 bit',
-      'key_type' => "encryption",
-      'key_type_settings[key_size]' => '128',
-      'key_provider' => 'config',
-      'key_input_settings[key_value]' => 'mustbesixteenbit',
-    ];
-    $this->drupalPostForm(NULL, $edit, t('Save'));
-
-    $this->testKeys['testing_key_128'] = \Drupal::service('key.repository')->getKey('testing_key_128');
-    $this->assertTrue($this->testKeys['testing_key_128'], 'Key was succesfully saved.');
-
-    // Create a 256bit testkey.
-    $this->drupalGet('admin/config/system/keys/add');
-    $edit = [
-      'key_type' => 'encryption',
-    ];
-    $this->drupalPostAjaxForm(NULL, $edit, 'key_type');
-    $edit = [
-      'key_provider' => 'config',
-    ];
-    $this->drupalPostAjaxForm(NULL, $edit, 'key_provider');
-
-    $edit = [
-      'id' => 'testing_key_256',
-      'label' => 'Testing Key 256 bit',
-      'key_type' => "encryption",
-      'key_type_settings[key_size]' => '256',
-      'key_provider' => 'config',
-      'key_input_settings[key_value]' => 'mustbesixteenbitmustbesixteenbit',
-    ];
-    $this->drupalPostForm(NULL, $edit, t('Save'));
-
-    $this->testKeys['testing_key_256'] = \Drupal::service('key.repository')->getKey('testing_key_256');
-    $this->assertTrue($this->testKeys['testing_key_256'], 'Key was succesfully saved.');
-  }
+class EncryptTest extends EncryptTestBase {
 
   /**
    * Test adding an encryption profile and encrypting / decrypting with it.
diff --git a/src/Tests/EncryptTestBase.php b/src/Tests/EncryptTestBase.php
new file mode 100644
index 0000000..d930092
--- /dev/null
+++ b/src/Tests/EncryptTestBase.php
@@ -0,0 +1,119 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\encrypt\Tests\EncryptTestBase.
+ */
+
+namespace Drupal\encrypt\Tests;
+
+use Drupal\encrypt\Entity\EncryptionProfile;
+use Drupal\key\Entity\Key;
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Defines a base class for tests.
+ *
+ * @group encrypt
+ */
+abstract class EncryptTestBase extends WebTestBase {
+
+  /**
+   * Modules to enable for this test.
+   *
+   * @var string[]
+   */
+  public static $modules = array('key', 'encrypt', 'encrypt_test');
+
+  /**
+   * An administrator user.
+   *
+   * @var \Drupal\user\Entity\User
+   */
+  protected $adminUser;
+
+  /**
+   * A list of testkeys.
+   *
+   * @var \Drupal\key\Entity\Key[]
+   */
+  protected $testKeys;
+
+  /**
+   * A list of test encryption profiles.
+   *
+   * @var \Drupal\encrypt\Entity\EncryptionProfile[]
+   */
+  protected $encryptionProfiles;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->adminUser = $this->drupalCreateUser([
+      'access administration pages',
+      'administer encrypt',
+      'administer keys',
+    ]);
+    $this->drupalLogin($this->adminUser);
+    $this->createTestKeys();
+    $this->createTestEncryptionProfiles();
+  }
+
+  /**
+   * Creates test keys for usage in tests.
+   */
+  protected function createTestKeys() {
+    // Create a 128bit testkey.
+    $key_128 = Key::create([
+      'id' => 'testing_key_128',
+      'label' => 'Testing Key 128 bit',
+      'key_type' => "encryption",
+      'key_type_settings' => ['key_size' => '128'],
+      'key_provider' => 'config',
+      'key_provider_settings' => ['key_value' => 'mustbesixteenbit'],
+    ]);
+    $key_128->save();
+    $this->testKeys['testing_key_128'] = $key_128;
+
+    // Create a 256bit testkey.
+    $key_256 = Key::create([
+      'id' => 'testing_key_256',
+      'label' => 'Testing Key 256 bit',
+      'key_type' => "encryption",
+      'key_type_settings[key_size]' => ['key_size' => '256'],
+      'key_provider' => 'config',
+      'key_provider_settings' => ['key_value' => 'mustbesixteenbitmustbesixteenbit'],
+    ]);
+    $key_256->save();
+    $this->testKeys['testing_key_256'] = $key_256;
+  }
+
+  /**
+   * Creates test encryption profiles for usage in tests.
+   */
+  protected function createTestEncryptionProfiles() {
+    // Create test encryption profiles.
+    $encryption_profile_1 = EncryptionProfile::create([
+      'id' => 'encryption_profile_1',
+      'label' => 'Encryption profile 1',
+      'encryption_method' => 'test_encryption_method',
+      'encryption_key' => $this->testKeys['testing_key_128']->id(),
+    ]);
+    $encryption_profile_1->save();
+    $this->encryptionProfiles['encryption_profile_1'] = $encryption_profile_1;
+
+    $encryption_profile_2 = EncryptionProfile::create([
+      'id' => 'encryption_profile_2',
+      'label' => 'Encryption profile 2',
+      'encryption_method' => 'config_test_encryption_method',
+      'encryption_method_configuration' => ['mode' => 'CFB'],
+      'encryption_key' => $this->testKeys['testing_key_256']->id(),
+    ]);
+    $encryption_profile_2->save();
+    $this->encryptionProfiles['encryption_profile_2'] = $encryption_profile_2;
+  }
+
+}
