function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Girbson Bijou 7Girbson Bijou 7 

Test class passed but unable to deploy yo production

In get the following message in the inbound change set.  Help me please
nventoryReportTest    TestInventoryReport    System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Container__c]: [Container__c]  Stack Trace: Class.InventoryReportTest.TestInventoryReport: line 20, column 1

My class is:

public with sharing class InventorySearchController { 
public list <Articles_Containers__c> inventoryItem {get;set;} 
public string searchstring {get;set;} 
public InventorySearchController( ) { 

public void search(){ 
string searchquery= 'select Name , Prod__c, UM__c, Container__c, Number__c, On_Hand__c,  Pending__c,  Available__c, Purpose__c, Condition__c, Age__c, Comments__c FROM Articles_Containers__c  WHERE Prod__c like \'%'+searchstring+'%\'  AND On_Hand__c >0  AND IsOpened__c = 1  Limit 50000';
      inventoryItem= Database.query(searchquery); 

public void clear(){ 


The test class is:

@isTest (SeeAllData=true)
public class InventorySearchTest {
    static testMethod void testMethod1(){
          Articles_Containers__c ac = new Articles_Containers__c();
          Product2 p = new Product2(Name ='TestProduct'); 
          Container__c c = new Container__c( Name = 'CMLU', Provenance__c='OTHER', Statut__c='Open');
           ac.Unit_Weight__c = 45; 
           ac.Unit_Cost__c = 87;
            ac.Container__c= c.ID;
             ac.Number__c = 54;
            ac.UM__c ='UNIT(S)';    
           ac.Local_ID__c = 7888;
           ac.Comments__c = 'UNIT(S)';
           ac.Condition__c= 'New';
           insert c;
           insert p;
           insert ac;
           InventorySearchController Inv = new  InventorySearchController();
             Inv.searchstring = 'testFullName';
Tory NethertonTory Netherton
Are you sure that test class is where the issue lies? The exception makes it seem as though the error is being generated by a test method called "TestInventoryReport" on a test class called "InventoryReportTest".
please navigate to Container__c object and check for the required fields , include them while you create an entry for Container__c in your test class