You need to sign in to do that
Don't have an account?
Test methods behaving apnormal
In a test class, I have written three test methods like
@isTest
public class TestClass
{
static testMethod void testMethod1()
{
Test.startTest();
System.debug('Current User Id: '+UserInfo.getUserId());
.....
.....
Test.stopTest();
}
static testMethod void testMethod2()
{
Test.startTest();
System.debug('Current User Id: '+UserInfo.getUserId());
.....
.....
Test.stopTest();
}
static testMethod void testMethod3()
{
Test.startTest();
System.debug('Current User Id: '+UserInfo.getUserId());
.....
.....
Test.stopTest();
}
static testMethod void testMethod4()
{
Test.startTest();
System.debug('Current User Id: '+UserInfo.getUserId());
.....
.....
Test.stopTest();
}
}
In this kind of scenario, a null pointer exception is coming from testMethod3, but in all the other methods it is not giving any error. I can't understand what is the reason of showing this error.
Please help me.
From the perspective of the big picture,it seems no error,But t would be better ,if you post ur all test code...
I am posting the third method where from the exception is coming
static testMethod void TestSubscription3()
{
ID sid;
List<String> subsid=new List<String>();
LIST<ID> acid=new LIST<ID>();
Test.startTest();
Account a=new Account (name='abcd',o2bc__Bill_Cycle__c='Yearly',o2bc__Activation_Date__c=date.today(),o2bc__Credit_Card_Number__c='411111111111',o2bc__Credit_Card_Type__c='Visa',o2bc__Expiry_Month__c='10',o2bc__Expiry_Year__c='2055');
insert a;
acid.add(a.id);
a.o2bc__Expiry_Year__c='2034';
Update a;
Contact c=new Contact (Account =a,Lastname='abc');
insert c;
o2bc__Item__c i=new o2bc__Item__c(Product_Code__c = 'E201', o2bc__Sell_Price__c=200.00, o2bc__Rental__c = 300.00, o2bc__Pricing__c = 'Flat',o2bc__Bill_Cycle__c='Monthly');
insert i;
o2bc__Item__c i1=new o2bc__Item__c(Product_Code__c = 'E201', o2bc__Sell_Price__c=300.00, o2bc__Rental__c =400.00, o2bc__Pricing__c = 'Flat',o2bc__Bill_Cycle__c='Yearly');
insert i1;
Discount__c D1Y=new Discount__c(Name='Discount 7%', Discount__c=7.00,Discount_Type__c='Percent',Start_Date__c=date.Today(), End_Date__c=date.Today().adddays(11),Unit_of_Discount_Period__c='Month',Discount_Period__c=10);
insert D1Y;
Discount__c D2M=new Discount__c(Name='Discount 7%', Discount__c=100.00,Discount_Type__c='Amount',Start_Date__c=date.Today(), End_Date__c=date.Today().adddays(12),Unit_of_Discount_Period__c='Month',Discount_Period__c=12);
insert D2M;
Discount__c D1Y2=new Discount__c(Name='Discount 7%', Discount__c=7.00,Discount_Type__c='Percent',Start_Date__c=date.Today(), End_Date__c=date.Today().adddays(14),Unit_of_Discount_Period__c='Month',Discount_Period__c=10);
insert D1Y2;
Discount__c D2M2=new Discount__c(Name='Discount 7%', Discount__c=100.00,Discount_Type__c='Amount',Start_Date__c=date.Today(), End_Date__c=date.Today().adddays(15),Unit_of_Discount_Period__c='Month',Discount_Period__c=12);
insert D2M2;
Campaign c12= new Campaign(Name='Campaign-test', Campaign_code__c='c-001', IsActive=true, StartDate=date.Today(), EndDate=date.Today().adddays(12));
insert c12;
Campaign_Discount__c CD1=new Campaign_Discount__c(Campaign__c=c12.id,Discount__c=D2M.id,Item__c=i.id,Seq__c='1');
insert CD1;
Campaign_Discount__c CD3=new Campaign_Discount__c(Campaign__c=c12.id,Discount__c=D2M2.id,Item__c=i.id,Seq__c='2');
insert CD3;
Campaign_Discount__c CD2=new Campaign_Discount__c(Campaign__c=c12.id,Discount__c=D1Y.id,Item__c=i1.id,Seq__c='1');
insert CD2;
Credit_Card__c cc3 = new Credit_Card__c(Account__c = a.Id, Active__c = true, CC_First_Name__c = 'S', CC_Last_Name__c = 'K', Credit_Card_Number__c = '4111111111111111', CC_Security_Code__c = '123', Credit_Card_Type__c = 'Visa', Expiry_Month__c = '8', Expiry_Year__c = '2012');
insert cc3;
List<Id> accountIds = new List<Id>();
accountIds.add(a.Id);
o2bc__Sales_Order__c order = new o2bc__Sales_Order__c(o2bc__Account__c=a.Id, o2bc__Order_date__c = date.today(), o2bc__Payment_Term__c = 'COD', o2bc__Shipping_Required__c = 'Yes', o2bc__Billing_City__c = a.BillingCity, o2bc__Billing_Country__c = a.BillingCountry, o2bc__Billing_State__c = a.BillingState, o2bc__Billing_Street__c = a.BillingStreet, o2bc__Order_Status__c = 'Open');
insert order;
o2bc__Order_Line__c ol = new o2bc__Order_Line__c(o2bc__Sales_Order__c = order.Id, o2bc__Item__c = i.Id, o2bc__Rented__c= true, o2bc__Quantity__c = 1);
insert ol;
o2bc.salesOrderExtController.processOrder(order.Id);
List<Id> invIds = o2bc.AnniversaryBill.generateSubscriptionsBill(accountIds, true);
Apexpages.Standardcontroller stdCon = new Apexpages.Standardcontroller(a);
SubscriptionExtController SEC = new SubscriptionExtController(stdCon);
SEC.isTest = true;
SEC.accId = a.Id;
SEC.doUpper = true;
o2bc__Sales_Order__c so1 = new o2bc__Sales_Order__c(o2bc__Account__c = a.ID, o2bc__Contact__c = c.Id);
insert so1;
SEC.sOrderTest = so1;
SEC.sOrder.Sales_Rep__c = Userinfo.getUserId(); // getting error from this line
........
........
}
In this code where I am using Userinfo.getUserId(), throwing the exception.
'Sales_Rep__c' ,is this a custom field that belongs to a custom object? The exception which you are getting is rising from null variable.It says that,'you can not set a null value'.It means,'Sales_Rep__c' is null.try to get instance of the related object in ur extension class.
I don't think this should be the reason, because I have also tried to print like
System.debug('Current User Id: '+UserInfo.getUserId());
But in this line too it is throwing the same exception.
You are right,your debug code made it clear...Thats weird.I think,you should look for any lilmitation for each test method.
For example,Only one user can execute just 2 test methods.I m just guessing..