How to Create Opportunity Product in Test Class?
Before wo go ahead and see how to create Opportunity Line Item in salesforce. Check the below diagram to see how Opportunity Line Item is related to multiple objects in salesforce.

How to Create order Line Item in salesforce Apex
Similarly see how to create Order line Item in apex
Keep Learning 🙂 #HappyLearning #DeveloperGeeks