我正在寻找测试控制器扩展的帮助。我不断收到错误消息:“System.QueryException: List has no rows for assignment to SObject”指的是我班级中的 SOQL 语句。
班级
public class productdata {
public productdata(ApexPages.StandardController controller) {
}
public String getTag(){
Product2 prod;
prod = [SELECT Name FROM Product2 WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
return Prod.Name;
}
测试班
@isTest
私有类 TestProductData { 静态 testMethod 无效 TestProductDataMethod(){
Product2 TP = new Product2(Name='TestRecord');
insert TP;
System.assertEquals('TestRecord', TP.name);
PageReference pageRef = page.productpage;
Test.setCurrentPage(pageRef);
ApexPages.StandardController sc = new ApexPages.standardController(TP);
productdata controller = new productdata(new ApexPages.StandardController(TP));
ApexPages.currentPage().getParameters().put('id', '01t300000007hKrAAI');
controller.getTag();
}
谢谢!