                 
                 if customization.status == .available {
                     trained = true
+                } else if customization.status == .failed {
+                    let message = "There was an error when training the customization, please " +
+                    "check and fix the errors before trying again."
+                    XCTFail(message)
                 }
                 expectation3.fulfill()
             }
             waitForExpectations()
             
             if tries > 10 {
-                XCTFail("Customization is not ready. Please check the customization errors.")
+                XCTFail("The customization is taking too long to train. Please try again later.")
             }
             
             sleep(3)
-        }
+        } while(!trained)
     }
     
     // MARK: - Models

                failure: failToGetCorpusStatus) { corpus in
                    
                    if corpus.status == .analyzed {
                        trained = true
                    }
                    expectation.fulfill()
            }
            waitForExpectations()
            
            if tries > 10 {
                XCTFail("The corpus has not been processed. Please check the corpus errors.")
            }
            
            sleep(3)
        }
        
        let description2 = "Train the customization with the new corpus."
        let expectation2 = self.expectation(description: description2)

                customization in
                
                if customization.status == .ready {
                    ready = true
                } else if customization.status == .failed {
                    let message = "The customization has failed, please fix the errors and try " +
                        "again later."
                    XCTFail(message)
                }
                expectation1.fulfill()
            }
            waitForExpectations()
            
            if tries > 10 {
                XCTFail("Customization is not ready. Please try again later.")
            }
            
            sleep(3)
        } while(!ready)
        
        let description2 = "Delete word1."
        let expectation2 = self.expectation(description: description2)
