diff --git tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
index 7288af6d63..113f67616d 100644
--- tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
+++ tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
@@ -33,7 +33,17 @@ class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post {
 		return wp_insert_attachment( $r, $r['file'], $r['post_parent'] );
 	}
 
-	function create_upload_object( $file, $parent = 0 ) {
+	/**
+	 * Upload a file and create an associated attachment post.
+	 *
+	 * @since 4.4.0
+	 *
+	 * @param string $file   Path of the file to upload and associate to the attachment.
+	 * @param int    $parent Optional. Attachment parent post id.
+	 *
+	 * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
+	 */
+	public function create_upload_object( $file, $parent = 0 ) {
 		$contents = file_get_contents( $file );
 		$upload   = wp_upload_bits( basename( $file ), null, $contents );
 
diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php
index fee06e0df9..4272a02d39 100644
--- tests/phpunit/includes/testcase.php
+++ tests/phpunit/includes/testcase.php
@@ -1032,6 +1032,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
 	 * Creates an attachment post from an uploaded file.
 	 *
 	 * @since 4.4.0
+	 * @deprecated 5.0.0 Use WP_UnitTest_Factory_For_Attachment::create_upload_object() instead.
 	 *
 	 * @param array $upload         Array of information about the uploaded file, provided by wp_upload_bits().
 	 * @param int   $parent_post_id Optional. Parent post ID.
@@ -1039,28 +1040,9 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
 	 * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
 	 */
 	function _make_attachment( $upload, $parent_post_id = 0 ) {
-		$type = '';
-		if ( ! empty( $upload['type'] ) ) {
-			$type = $upload['type'];
-		} else {
-			$mime = wp_check_filetype( $upload['file'] );
-			if ( $mime ) {
-				$type = $mime['type'];
-			}
-		}
-
-		$attachment = array(
-			'post_title'     => basename( $upload['file'] ),
-			'post_content'   => '',
-			'post_type'      => 'attachment',
-			'post_parent'    => $parent_post_id,
-			'post_mime_type' => $type,
-			'guid'           => $upload['url'],
-		);
+		trigger_error( __METHOD__ . ' is deprecated since version 5.0.0. Use WP_UnitTest_Factory_For_Attachment::create_upload_object() instead' );
 
-		$id = wp_insert_attachment( $attachment, $upload['file'], $parent_post_id );
-		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
-		return $id;
+		return self::factory()->attachment->create_upload_object( $upload['file'], $parent_post_id );
 	}
 
 	/**
diff --git tests/phpunit/tests/ajax/Attachments.php tests/phpunit/tests/ajax/Attachments.php
index cf11ddc5a0..31012f687d 100644
--- tests/phpunit/tests/ajax/Attachments.php
+++ tests/phpunit/tests/ajax/Attachments.php
@@ -26,11 +26,7 @@ class Tests_Ajax_Attachments extends WP_Ajax_UnitTestCase {
 		wp_set_current_user( $user_id );
 		$_POST = array_merge( $_POST, $post );
 
-		$filename = DIR_TESTDATA . '/images/canola.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload     = wp_upload_bits( basename( $filename ), null, $contents );
-		$attachment = $this->_make_attachment( $upload );
+		$attachment = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' );
 
 		// Set up a default request
 		$_POST['nonce']      = wp_create_nonce( 'media-send-to-editor' );
@@ -77,11 +73,7 @@ class Tests_Ajax_Attachments extends WP_Ajax_UnitTestCase {
 		wp_set_current_user( $user_id );
 		$_POST = array_merge( $_POST, $post );
 
-		$filename = DIR_TESTDATA . '/formatting/entities.txt';
-		$contents = file_get_contents( $filename );
-
-		$upload     = wp_upload_bits( basename( $filename ), null, $contents );
-		$attachment = $this->_make_attachment( $upload );
+		$attachment = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/formatting/entities.txt' );
 
 		// Set up a default request
 		$_POST['nonce']      = wp_create_nonce( 'media-send-to-editor' );
diff --git tests/phpunit/tests/ajax/MediaEdit.php tests/phpunit/tests/ajax/MediaEdit.php
index a55e3829a8..892893be1b 100644
--- tests/phpunit/tests/ajax/MediaEdit.php
+++ tests/phpunit/tests/ajax/MediaEdit.php
@@ -29,11 +29,7 @@ class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase {
 	public function testCropImageThumbnail() {
 		include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
 
-		$filename = DIR_TESTDATA . '/images/canola.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$id     = $this->_make_attachment( $upload );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' );
 
 		$_REQUEST['action']  = 'image-editor';
 		$_REQUEST['context'] = 'edit-attachment';
@@ -60,11 +56,7 @@ class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase {
 
 		include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
 
-		$filename = DIR_TESTDATA . '/images/canola.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$id     = $this->_make_attachment( $upload );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/canola.jpg' );
 
 		$_REQUEST['action']  = 'image-editor';
 		$_REQUEST['context'] = 'edit-attachment';
diff --git tests/phpunit/tests/general/template.php tests/phpunit/tests/general/template.php
index 05ef9777d8..c0423afe4f 100644
--- tests/phpunit/tests/general/template.php
+++ tests/phpunit/tests/general/template.php
@@ -228,14 +228,8 @@ class Tests_General_Template extends WP_UnitTestCase {
 	 * @since 4.3.0
 	 */
 	function _insert_attachment() {
-		$filename = DIR_TESTDATA . '/images/test-image.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload              = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->site_icon_url = $upload['url'];
-
-		// Save the data
-		$this->site_icon_id = $this->_make_attachment( $upload );
+		$this->site_icon_id  = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
+		$this->site_icon_url = wp_get_attachment_url( $this->site_icon_id );
 		return $this->site_icon_id;
 	}
 
@@ -404,13 +398,8 @@ class Tests_General_Template extends WP_UnitTestCase {
 	 * @since 4.5.0
 	 */
 	function _insert_custom_logo() {
-		$filename = DIR_TESTDATA . '/images/test-image.jpg';
-		$contents = file_get_contents( $filename );
-		$upload   = wp_upload_bits( basename( $filename ), null, $contents );
-
-		// Save the data.
-		$this->custom_logo_url = $upload['url'];
-		$this->custom_logo_id  = $this->_make_attachment( $upload );
+		$this->custom_logo_id  = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
+		$this->custom_logo_url = wp_get_attachment_url( $this->custom_logo_id );
 		return $this->custom_logo_id;
 	}
 
diff --git tests/phpunit/tests/image/intermediateSize.php tests/phpunit/tests/image/intermediateSize.php
index 95ee173edd..99b94bea21 100644
--- tests/phpunit/tests/image/intermediateSize.php
+++ tests/phpunit/tests/image/intermediateSize.php
@@ -15,13 +15,6 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
 		parent::tearDown();
 	}
 
-	public function _make_attachment( $file, $parent_post_id = 0 ) {
-		$contents = file_get_contents( $file );
-		$upload   = wp_upload_bits( basename( $file ), null, $contents );
-
-		return parent::_make_attachment( $upload, $parent_post_id );
-	}
-
 	function test_make_intermediate_size_no_size() {
 		$image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 0, false );
 
@@ -71,8 +64,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
 	function test_get_intermediate_sizes_by_name() {
 		add_image_size( 'test-size', 330, 220, true );
 
-		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
 
 		// look for a size by name
 		$image = image_get_intermediate_size( $id, 'test-size' );
@@ -94,8 +86,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
 		add_image_size( 'false-height', 330, 400, true );
 		add_image_size( 'false-width', 600, 220, true );
 
-		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
 
 		// look for a size by array that exists
 		// note: staying larger than 300px to miss default medium crop
@@ -116,8 +107,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
 		add_image_size( 'false-height', 330, 100, true );
 		add_image_size( 'false-width', 150, 220, true );
 
-		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
 
 		// look for a size by array that doesn't exist
 		// note: staying larger than 300px to miss default medium crop
@@ -137,8 +127,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
 		add_image_size( 'false-height', 330, 100, true );
 		add_image_size( 'false-width', 150, 220, true );
 
-		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
 
 		// look for a size by array that doesn't exist
 		// note: staying larger than 300px to miss default medium crop
@@ -160,8 +149,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
 		add_image_size( 'test-size', $random_w, 0, false );
 		add_image_size( 'false-height', $random_w, 100, true );
 
-		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
 
 		$original = wp_get_attachment_metadata( $id );
 		$image_w  = $random_w;
@@ -188,8 +176,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
 		add_image_size( 'test-size', 0, $height, false );
 		add_image_size( 'false-height', 300, $height, true );
 
-		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
 
 		$original = wp_get_attachment_metadata( $id );
 		$image_h  = $height;
@@ -214,8 +201,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
 		$height = 201;
 		add_image_size( 'off-by-one', $width, $height, true );
 
-		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
 
 		$original = wp_get_attachment_metadata( $id );
 		$image_h  = $height;
@@ -235,8 +221,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
 		// Add a hard cropped size that matches the aspect ratio we're going to test.
 		add_image_size( 'test-size', 200, 100, true );
 
-		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
 
 		// Request a size by array that doesn't exist and is smaller than the 'thumbnail'
 		$image = image_get_intermediate_size( $id, array( 50, 25 ) );
@@ -249,8 +234,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
 	 * @ticket 34384
 	 */
 	public function test_get_intermediate_size_with_small_size_array_fallback() {
-		$file = DIR_TESTDATA . '/images/waffles.jpg';
-		$id   = $this->_make_attachment( $file, 0 );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/waffles.jpg' );
 
 		$original       = wp_get_attachment_metadata( $id );
 		$thumbnail_file = $original['sizes']['thumbnail']['file'];
diff --git tests/phpunit/tests/image/siteIcon.php tests/phpunit/tests/image/siteIcon.php
index 509b69f975..974dfe6b04 100644
--- tests/phpunit/tests/image/siteIcon.php
+++ tests/phpunit/tests/image/siteIcon.php
@@ -156,16 +156,10 @@ class Tests_WP_Site_Icon extends WP_UnitTestCase {
 	}
 
 	function _insert_attachment() {
-		if ( $this->attachment_id ) {
-			return $this->attachment_id;
+		if ( ! $this->attachment_id ) {
+			$this->attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
 		}
 
-		$filename = DIR_TESTDATA . '/images/test-image.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-
-		$this->attachment_id = $this->_make_attachment( $upload );
 		return $this->attachment_id;
 	}
 }
diff --git tests/phpunit/tests/post/attachments.php tests/phpunit/tests/post/attachments.php
index 08e44500f8..21813ab02f 100644
--- tests/phpunit/tests/post/attachments.php
+++ tests/phpunit/tests/post/attachments.php
@@ -22,15 +22,8 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 	}
 
 	function test_insert_image_no_thumb() {
-
 		// this image is smaller than the thumbnail size so it won't have one
-		$filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
-		$id = $this->_make_attachment( $upload );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
 
 		// intermediate copies should not exist
 		$this->assertFalse( image_get_intermediate_size( $id, 'thumbnail' ) );
@@ -39,17 +32,17 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 
 		// medium, medium_large, and full size will both point to the original
 		$downsize = image_downsize( $id, 'medium' );
-		$this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) );
+		$this->assertEquals( basename( wp_get_attachment_url( $id ) ), basename( $downsize[0] ) );
 		$this->assertEquals( 50, $downsize[1] );
 		$this->assertEquals( 50, $downsize[2] );
 
 		$downsize = image_downsize( $id, 'medium_large' );
-		$this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) );
+		$this->assertEquals( basename( wp_get_attachment_url( $id ) ), basename( $downsize[0] ) );
 		$this->assertEquals( 50, $downsize[1] );
 		$this->assertEquals( 50, $downsize[2] );
 
 		$downsize = image_downsize( $id, 'full' );
-		$this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) );
+		$this->assertEquals( basename( wp_get_attachment_url( $id ) ), basename( $downsize[0] ) );
 		$this->assertEquals( 50, $downsize[1] );
 		$this->assertEquals( 50, $downsize[2] );
 
@@ -63,13 +56,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 		update_option( 'medium_size_w', 0 );
 		update_option( 'medium_size_h', 0 );
 
-		$filename = ( DIR_TESTDATA . '/images/a2-small.jpg' );
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
-		$id = $this->_make_attachment( $upload );
+		$id =  self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/a2-small.jpg' );;
 
 		// intermediate copies should exist: thumbnail only
 		$thumb = image_get_intermediate_size( $id, 'thumbnail' );
@@ -119,13 +106,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 		update_option( 'medium_large_size_w', 600 );
 		update_option( 'medium_large_size_h', 0 );
 
-		$filename = ( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' );
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
-		$id      = $this->_make_attachment( $upload );
+		$id      = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' );
 		$uploads = wp_upload_dir();
 
 		// intermediate copies should exist: thumbnail and medium
@@ -178,13 +159,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 		update_option( 'medium_large_size_w', 600 );
 		update_option( 'medium_large_size_h', 0 );
 
-		$filename = ( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' );
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
-		$id      = $this->_make_attachment( $upload );
+		$id      = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' );;
 		$uploads = wp_upload_dir();
 
 		// check that the file and intermediates exist
@@ -220,31 +195,19 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 	 * @ticket 21963
 	 */
 	function test_insert_image_without_guid() {
-		// this image is smaller than the thumbnail size so it won't have one
-		$filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
-		$contents = file_get_contents( $filename );
+		$attachment_id = self::factory()->attachment->create( array( 'file' => '' ) );
 
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
-		$upload['url'] = '';
-		$id            = $this->_make_attachment( $upload );
+		$guid = get_the_guid( $attachment_id );
 
-		$guid = get_the_guid( $id );
 		$this->assertFalse( empty( $guid ) );
+		$this->assertContains( '?attachment_id=' . $attachment_id, $guid );
 	}
 
 	/**
 	 * @ticket 21963
 	 */
 	function test_update_attachment_fields() {
-		$filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
-		$id = $this->_make_attachment( $upload );
+		$id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
 
 		$attached_file = get_post_meta( $id, '_wp_attached_file', true );
 
@@ -264,13 +227,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 	 * @ticket 29646
 	 */
 	function test_update_orphan_attachment_parent() {
-		$filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
-		$attachment_id = $this->_make_attachment( $upload );
+		$attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
 
 		// Assert that the attachment is an orphan
 		$attachment = get_post( $attachment_id );
@@ -296,14 +253,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 		$siteurl = get_option( 'siteurl' );
 		update_option( 'siteurl', set_url_scheme( $siteurl, 'http' ) );
 
-		$filename = DIR_TESTDATA . '/images/test-image.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
-		// Set attachment ID.
-		$attachment_id = $this->_make_attachment( $upload );
+		$attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
 
 		$_SERVER['HTTPS'] = 'off';
 
@@ -321,14 +271,8 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 		$siteurl = get_option( 'siteurl' );
 		update_option( 'siteurl', set_url_scheme( $siteurl, 'https' ) );
 
-		$filename = DIR_TESTDATA . '/images/test-image.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
 		// Set attachment ID.
-		$attachment_id = $this->_make_attachment( $upload );
+		$attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
 
 		$_SERVER['HTTPS'] = 'off';
 
@@ -346,14 +290,8 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 		$siteurl = get_option( 'siteurl' );
 		update_option( 'siteurl', set_url_scheme( $siteurl, 'http' ) );
 
-		$filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
 		// Set attachment ID
-		$attachment_id = $this->_make_attachment( $upload );
+		$attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
 
 		$_SERVER['HTTPS'] = 'on';
 
@@ -374,14 +312,8 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 		$siteurl = get_option( 'siteurl' );
 		update_option( 'siteurl', set_url_scheme( $siteurl, 'https' ) );
 
-		$filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
 		// Set attachment ID.
-		$attachment_id = $this->_make_attachment( $upload );
+		$attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
 
 		$_SERVER['HTTPS'] = 'on';
 
@@ -402,14 +334,8 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 		$siteurl = get_option( 'siteurl' );
 		update_option( 'siteurl', set_url_scheme( $siteurl, 'http' ) );
 
-		$filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
 		// Set attachment ID
-		$attachment_id = $this->_make_attachment( $upload );
+		$attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
 
 		$_SERVER['HTTPS'] = 'on';
 		set_current_screen( 'dashboard' );
@@ -429,14 +355,8 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 		// Set https upload URL
 		add_filter( 'upload_dir', '_upload_dir_https' );
 
-		$filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
-		$contents = file_get_contents( $filename );
-
-		$upload = wp_upload_bits( basename( $filename ), null, $contents );
-		$this->assertTrue( empty( $upload['error'] ) );
-
 		// Set attachment ID
-		$attachment_id = $this->_make_attachment( $upload );
+		$attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );;
 
 		$_SERVER['HTTPS'] = 'on';
 		set_current_screen( 'dashboard' );
@@ -451,11 +371,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 	}
 
 	public function test_wp_attachment_is() {
-		$filename = DIR_TESTDATA . '/images/test-image.jpg';
-		$contents = file_get_contents( $filename );
-
-		$upload        = wp_upload_bits( basename( $filename ), null, $contents );
-		$attachment_id = $this->_make_attachment( $upload );
+		$attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.jpg' );
 
 		$this->assertTrue( wp_attachment_is_image( $attachment_id ) );
 		$this->assertTrue( wp_attachment_is( 'image', $attachment_id ) );
@@ -469,11 +385,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase {
 			add_filter( 'upload_mimes', array( $this, 'whitelist_psd_mime_type' ), 10, 2 );
 		}
 
-		$filename = DIR_TESTDATA . '/images/test-image.psd';
-		$contents = file_get_contents( $filename );
-
-		$upload        = wp_upload_bits( basename( $filename ), null, $contents );
-		$attachment_id = $this->_make_attachment( $upload );
+		$attachment_id = self::factory()->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.psd' );
 
 		$this->assertFalse( wp_attachment_is_image( $attachment_id ) );
 		$this->assertTrue( wp_attachment_is( 'psd', $attachment_id ) );
diff --git tests/phpunit/tests/xmlrpc/wp/getMediaItem.php tests/phpunit/tests/xmlrpc/wp/getMediaItem.php
index e036a7f4b9..3759343191 100644
--- tests/phpunit/tests/xmlrpc/wp/getMediaItem.php
+++ tests/phpunit/tests/xmlrpc/wp/getMediaItem.php
@@ -18,11 +18,10 @@ class Tests_XMLRPC_wp_getMediaItem extends WP_XMLRPC_UnitTestCase {
 
 		add_theme_support( 'post-thumbnails' );
 
-		$filename = ( DIR_TESTDATA . '/images/waffles.jpg' );
-		$contents = file_get_contents( $filename );
-		$upload   = wp_upload_bits( basename( $filename ), null, $contents );
-
-		$this->attachment_id   = $this->_make_attachment( $upload, self::$post_id );
+		$this->attachment_id   = self::factory()->attachment->create_upload_object(
+			DIR_TESTDATA . '/images/waffles.jpg',
+			self::$post_id
+		);
 		$this->attachment_data = get_post( $this->attachment_id, ARRAY_A );
 
 		set_post_thumbnail( self::$post_id, $this->attachment_id );
