6

I have a class QuoteMachinesCartController

public class QuoteMachinesCartController {
public String opportunityId{set; get;}
public String name{set; get;}
public String paste{set; get;}

//
public Opportunity getOpportunity() {
    if(opportunityId == null) {
        opportunityId = ApexPages.currentPage().getParameters().get('OpportunityId');
    }
    return [select Id, Name, AccountId from Opportunity where Id=:opportunityId];
}

public Account getAccount() {
    system.debug('getAccount');
    String id = getOpportunity().AccountId;
    return [select Id, Language__c from Account where Id = :id];
}

//Database.Query(strSoql);  Use this for creating string queries for SOQL
public PageReference save() {
    Pricebook2 pb = [select Id from Pricebook2 where isStandard=true limit 1];

    Quote q = new Quote(Name=name, OpportunityId=opportunityId, Pricebook2Id=pb.Id);
    insert q;

    String pid = '';

    // items
    List<String> items = paste.split(':::::');

    // Product2Id, Descripcion, Quantity, Price
    for(String item : items ) {
        List<String> params = item.split(':::');
        //System.debug('Params: ' + params);////
        pid = params[0];
        PricebookEntry pbook = [SELECT Id FROM PricebookEntry WHERE Product2Id = :pid];

        QuoteLineItem qi = new QuoteLineItem(
            QuoteId=q.Id,
            Description__c = params[1],
            PricebookEntryId=pbook.Id,
            Quantity=Decimal.valueOf(params[2]),
            UnitPrice=Decimal.valueOf(params[3])
        );

        insert qi;
    }

    PageReference page = new ApexPages.StandardController(q).view();
    page.setRedirect(true);
    return page;
}

}

And the test:

@isTest(seeAllData=true)
class QuoteMachinesCartControllerTest {

public static testMethod void testSave() {
    String txt = '01t90000001xTD2AAM:::Manufacturer: Steelhaed \nYear: 2001\n19 ltr. Gallonen Anlage,\nWaschmaschine, Füller u. Verschließer\n:::1:::1:::3714:::/system/attachments/production/000/010/401/medium-6de2c3ec9f0f06df2551915b54b687be.jpg?1365143558:::::01t90000001xT2CAAU:::Year: 1993\n12 valves Rinser. See attached. Only water tratement. it has a\ndisposal: no spray-no bottle.\nRegular speed inverter\nThree types bottle.\n:::2:::15000:::3713:::/system/attachments/production/000/010/400/medium-a611ab5bbc002f5fd24dc754c79ee492.jpg?1365100471:::::01t90000001xT2BAAU:::Year: null\nVerschneidebock:::1:::1500:::3712:::/system/attachments/production/000/010/386/medium-dbebf06f0117f92a118c9fdb487308b7.jpg?1364978822:::::01t90000001xTCzAAM:::Manufacturer: Seitz\nYear: 1977\nwith 27 intermidiate plastic sheets and 2 end-plates, without bin:::1:::4900:::3706:::/system/attachments/production/000/010/339/medium-474447ca18c2df0c2c342d8d1e892e1d.jpg?1364287065';
    String name = 'Test quote QuoteMachinesCartController';

    // Test for Controller
    QuoteMachinesCartController quote = new QuoteMachinesCartController();

    //Opportunity op = [select Id, Name from Opportunity where Id='006O0000003NLSr'];

    //System.assertEquals(op.Id, '006O0000003NLSr');
    quote.opportunityId = '006O0000003NLSr';
    quote.name = name;
    quote.paste = txt;

    quote.save();

    Quote q = [select Id, Name from Quote where Name=:name];

    system.debug('Quote Name:' + q.Name);
    system.debug('Quote Id:' + q.Id);
    System.assertEquals(q.Name, name);

    List<QuoteLineitem> items = [select Description__c, UnitPrice, Quantity from QuoteLineitem where QuoteId=:q.Id];
    System.assertEquals(items.size(), 4);

    for(QuoteLineItem item : items) {
      if(item.UnitPrice == 15000) {
        system.assertEquals(item.Quantity, 2);
      }
    }

    System.assertEquals(items[0].UnitPrice, 1);
    System.assertEquals(items[0].Quantity, 1);

}

public static testMethod void testGetOpportunity() {
    CreateQuoteFromPasteController licont = new CreateQuoteFromPasteController();
    Opportunity op = [select Name, Id from Opportunity limit 1];
    licont.opportunityId = op.Id;

    system.assertEquals(licont.getOpportunity().Name, op.Name);
}
}

But my code coverage for QuoteMachinesCartController stills on 0% what is wrong, ahh by the way I have my class with Override Log Filters, but I have tried to change that but does not work, is that the reason the code coverage is is in 0%. Ahh this is on a sandbox

enter image description here

  • 1
    Where is the 0% code coverage being reported? I.e. Is it during packaging/deployment or is it after Apex Classes > Run All Tests. As a quick idea, try using the Clear Code Coverage button and View Test History > Clear Test Results first before using Run All Tests. – Daniel Ballinger Oct 2 '13 at 19:48
  • Also make sure your tests pass if you want the coverage to update. – Adrian Larson Oct 2 '13 at 22:12
  • Yes my test pass but I'm not sure why when I go to the class I see 0% – Boris Barroso Oct 2 '13 at 22:20
  • What happens if you try to run the tests in the Developer Console? It has a panel that shows code coverage. – Mike Chale Oct 16 '13 at 18:31
  • How are you running your test methods? From the Dev Console, from Eclipse or directly from the web UI when displaying the QuoteMachinesCartControllerTest class? – JLiljegren__c Oct 17 '13 at 8:15
1

These are all long shots but a few things to try:

  1. It may be worth checking if the option to 'Store Only Aggregated Code Coverage' is enabled or not. Navigate to the test case and click 'Run Test', when the page loads, untick the checkbox next to 'Store Only Aggregated Code Coverage', click 'OK'. Navigate back to the developer console and run all the tests again.

  2. Try clicking the 'Compile all classes' on the Apex Classes page. Then run all tests again.

I hope one of these helps.

|improve this answer|||||
1

To Know what lines have been covered and what is the code coverage of your test class,The best way is to use Developer Console.

When you open the Developer Console, you will see a section on the bottom right hand corner for overall code coverage.

You can click on the test class for which you want to know the coverage.

Before this, you need to run the particular test class or all test classes. So go to setup --> apex test execution --> options --> uncheck the 'Store Only Aggregated Code Coverage' option and then Run the QuoteMachinesCartControllerTest test class.

Navigate back to the developer console to check the code coverage.

|improve this answer|||||
-4

(workaround) Edit and save the APEX classes from Salesforce UI actually worked for me.

|improve this answer|||||
  • 1
    Hi, this is a very bad answer for a good question. It's best if you update your answer. – Saariko Oct 16 '13 at 18:04
  • This answer doesn't include any detail about what worked. What exactly does "worked" mean? – Nathan Williams Oct 16 '13 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.