diff --git tests/phpunit/tests/media/getAttachmentTaxonomies.php tests/phpunit/tests/media/getAttachmentTaxonomies.php
index c78ce6aa81..ae6735a701 100644
--- tests/phpunit/tests/media/getAttachmentTaxonomies.php
+++ tests/phpunit/tests/media/getAttachmentTaxonomies.php
@@ -5,79 +5,51 @@
  * @group taxonomy
  */
 class Tests_Media_GetAttachmentTaxonomies extends WP_UnitTestCase {
+	/**
+	 * Instance of a JPEG image attachment.
+	 *
+	 * @var WP_Post;
+	 */
+	public static $attachment;
+
+	public static function wpSetUpBeforeClass( $factory ) {
+		self::$attachment = get_post(
+			$factory->attachment->create_object( array(
+				'file'           => 'image.jpg',
+				'post_mime_type' => 'image/jpeg',
+				'post_type'      => 'attachment',
+			) )
+		);
+	}
+
 	public function test_should_return_attachment_taxonomy() {
 		register_taxonomy( 'wptests_tax', 'attachment' );
 
-		$a = self::factory()->attachment->create_object( 'image.jpg', 0, array(
-			'post_mime_type' => 'image/jpeg',
-			'post_type' => 'attachment'
-		) );
-		$attachment = get_post( $a );
-
-		$found = get_attachment_taxonomies( $attachment, 'names' );
-		$expected = array( 'wptests_tax' );
-
-		$this->assertSame( $expected, $found );
+		$this->assertSame( get_attachment_taxonomies( self::$attachment, 'names' ), array( 'wptests_tax' ) );
 	}
 
 	public function test_should_return_taxonomy_registered_for_specific_attachment_type() {
 		register_taxonomy( 'wptests_tax', 'attachment:image' );
 
-		$a = self::factory()->attachment->create_object( 'image.jpg', 0, array(
-			'post_mime_type' => 'image/jpeg',
-			'post_type' => 'attachment'
-		) );
-		$attachment = get_post( $a );
-
-		$found = get_attachment_taxonomies( $attachment, 'names' );
-		$expected = array( 'wptests_tax' );
-
-		$this->assertSame( $expected, $found );
+		$this->assertSame( get_attachment_taxonomies( self::$attachment, 'names' ), array( 'wptests_tax' ) );
 	}
 
 	public function test_should_return_taxonomy_registered_for_specific_attachment_mimetype() {
 		register_taxonomy( 'wptests_tax', 'attachment:image/jpeg' );
 
-		$a = self::factory()->attachment->create_object( 'image.jpg', 0, array(
-			'post_mime_type' => 'image/jpeg',
-			'post_type' => 'attachment'
-		) );
-		$attachment = get_post( $a );
-
-		$found = get_attachment_taxonomies( $attachment, 'names' );
-		$expected = array( 'wptests_tax' );
-
-		$this->assertSame( $expected, $found );
+		$this->assertSame( get_attachment_taxonomies( self::$attachment, 'names' ), array( 'wptests_tax' ) );
 	}
 
 	public function test_should_return_taxonomy_registered_for_specific_file_extension() {
 		register_taxonomy( 'wptests_tax', 'attachment:jpg' );
 
-		$a = self::factory()->attachment->create_object( 'image.jpg', 0, array(
-			'post_mime_type' => 'image/jpeg',
-			'post_type' => 'attachment'
-		) );
-		$attachment = get_post( $a );
-
-		$found = get_attachment_taxonomies( $attachment, 'names' );
-		$expected = array( 'wptests_tax' );
-
-		$this->assertSame( $expected, $found );
+		$this->assertSame( get_attachment_taxonomies( self::$attachment, 'names' ), array( 'wptests_tax' ) );
 	}
 
 	public function test_should_not_return_duplicate_taxonomies() {
 		register_taxonomy( 'wptests_tax', array( 'attachment', 'attachment:image/jpeg' ) );
 
-		$a = self::factory()->attachment->create_object( 'image.jpg', 0, array(
-			'post_mime_type' => 'image/jpeg',
-			'post_type' => 'attachment'
-		) );
-		$attachment = get_post( $a );
-
-		$found = get_attachment_taxonomies( $attachment, 'names' );
-		$expected = array( 'wptests_tax' );
-
-		$this->assertSame( $expected, $found );
+		$this->assertSame( get_attachment_taxonomies( self::$attachment, 'names' ), array( 'wptests_tax' ) );
 	}
 
 	/**
@@ -86,33 +58,20 @@ class Tests_Media_GetAttachmentTaxonomies extends WP_UnitTestCase {
 	public function test_should_respect_output_objects() {
 		register_taxonomy( 'wptests_tax2', 'attachment:image' );
 
-		$a = self::factory()->attachment->create_object( 'image.jpg', 0, array(
-			'post_mime_type' => 'image/jpeg',
-			'post_type' => 'attachment'
-		) );
-		$attachment = get_post( $a );
-
-		$found = get_attachment_taxonomies( $attachment, 'objects' );
+		$found = get_attachment_taxonomies( self::$attachment, 'objects' );
 
 		$this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) );
 		$this->assertInternalType( 'object', $found['wptests_tax2'] );
 		$this->assertSame( 'wptests_tax2', $found['wptests_tax2']->name );
 	}
 
-
 	/**
 	 * @ticket 37368
 	 */
 	public function test_should_return_unique_taxonomies_for_output_objects() {
 		register_taxonomy( 'wptests_tax2', array( 'attachment:image', 'attachment:image/jpeg' ) );
 
-		$a = self::factory()->attachment->create_object( 'image.jpg', 0, array(
-			'post_mime_type' => 'image/jpeg',
-			'post_type' => 'attachment'
-		) );
-		$attachment = get_post( $a );
-
-		$found = get_attachment_taxonomies( $attachment, 'objects' );
+		$found = get_attachment_taxonomies( self::$attachment, 'objects' );
 
 		$this->assertSame( array( 'wptests_tax2' ), array_keys( $found ) );
 		$this->assertInternalType( 'object', $found['wptests_tax2'] );
