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
Mick ManMick Man 

test class

I am new to Salesforce, I try to create a test class, I think I succeeded, but my coach was not yet satisfied, but I do not know now what this test class, the problem is that c I only have two days today and tomorrow to do it, if not, I'm not allowed to support my report
this is my class
public class NouveauProduitExtensions 
    {
         public List<cMatiere> matiereList {get; set;}
         public List<JointMatProd__c> JointList {get; set;}
         public List<MatierePremiere__c> selectedMatieres{get;set;}
         public Integer value {get;set;} 

         public NouveauProduitExtensions(ApexPages.StandardController controller) 
             {
                 
             }
    
        public PageReference cancel() 
            {
                return Page.Nouveau_produit;
            }
        public JointMatProd__c Jointure {get; set;} 

        public Produit__c prod { get; set; }

        public NouveauProduitExtensions() 
            {
                prod = new Produit__c();
        
                Jointure = new JointMatProd__c();
            }
    
        public PageReference showAddMatierePage() 
            {
                return Page.Produit_Add_Matiere;
            }
    
        public PageReference Save() 
            {
                insert prod;
                List<JointMatProd__c> JointSave = new  List<JointMatProd__c>();
                 for (JointMatProd__c jl : JointList)
                     {
                         JointSave.add(new jointMatProd__c(Produit__c = prod.id, MatierePremiere__c = jl.MatierePremiere__c, Quantite__c = jl.Quantite__c));
                     }
                insert JointSave;
                PageReference acctPage = new ApexPages.StandardController(prod).view();

                acctPage.setRedirect(true);

                return acctPage;
            }

        public List<cMatiere> getMatieres() 

            {
                if(matiereList == null) 
                    {
                        matiereList = new List<cMatiere>();
                        for(MatierePremiere__c c : [select Id, Name, Unite__c from MatierePremiere__c])
    
                           {

                               matiereList.add(new cMatiere(c));
                           }
                  }
                  return matiereList;
             }  
    
        public PageReference processSelected()

            {
                selectedMatieres = new List<MatierePremiere__c>();
                JointList = new List<JointMatProd__c>(); 
                for (cMatiere cMat : getMatieres()) 
                    {
                        if(cMat.selected == true) 
                            {
                                selectedMatieres.add(cMat.mat);
                            }
                    }
                value = selectedMatieres.size();
                System.debug('printing listcontc'+selectedMatieres.size());
                for (MatierePremiere__c mat : selectedMatieres)
                    {
                        JointList.add(new jointMatProd__c(Produit__c = prod.id, MatierePremiere__c = mat.id, Quantite__c=0));
                    }

                return page.Nouveau_produit;

             }

             public class cMatiere

                {
                    public MatierePremiere__c mat {get; set;}
                    public Boolean selected {get; set;}

                    public cMatiere(MatierePremiere__c c) 
                        {
                            mat = c;
                            selected = false;
                        }
                }


}

and here's the test
@isTest(SeeAllData=true)
public class TestDataAccessClass {

    static testmethod void ProdTestMethod() {
        Produit__c prod = [SELECT Id, Name FROM Produit__c WHERE Name='Oli-c' LIMIT 1];
        System.assert(prod != null);
        
        Produit__c testProd = prod.clone();
        testProd.Name = 'test prod';
        insert testProd;
        
        Produit__c testProd2 = [SELECT Id, Name FROM Produit__c WHERE Name='test prod' LIMIT 1];
        System.assert(testProd2 != null);
    }
 
 static void JointTestMethod() {
    JointMatProd__c joint = [SELECT  Id, Name, MatierePremiere__c, Produit__c, Quantite__c FROM JointMatProd__c WHERE Name='17' LIMIT 1];
    System.assert(joint != null);
    
    JointMatProd__c testJoint = joint.clone();
    //testJoint.Name = '';
    testJoint.MatierePremiere__c = 'Couvercle alu test';
    testJoint.Quantite__c = 12;
    
    JointMatProd__c testJoint2 = [SELECT Id, Name, MatierePremiere__c, Quantite__c FROM JointMatProd__c WHERE MatierePremiere__c='Couvercle alu test' LIMIT 1];
   }
  
}

Can someone help me please
KaranrajKaranraj
I strongly recommend you to take the Apex Test class module in Trailhead. https://developer.salesforce.com/trailhead/apex_testing/apex_testing_intro which gives in dept knowledge to write a better test class and its best practices to follow.
Sagar PareekSagar Pareek
Hi Micky,

This video will give you perfect guidance on writting test class

https://www.youtube.com/watch?v=n9amswhOxJw