You need to sign in to do that
Don't have an account?

Testing inner classes
I have a trigger that invokes a callout on insert of a custom object.
In the test below, I only get 33 % code coverage, since the inner classes Response and Data isn't covered by the test. How can I test them?
My class:
public with sharing class OuterClass { @future (callout=true) public static void doCallout() { //Callout occurs here normally, but to simplify: String body = '{"status":1,"data":[{"id":"33e26b70-ec3e-11e1-bbc0-bfcb6088709b","name":"Testname","created":"2012-08-16T14:24:32"}]}'; getData(body); } public static void getData(String body) { Response r = (Response) JSON.deserialize(body, Response.class); System.debug(r.status); for (Data d : r.data) { System.debug('d.id: ' + d.id); } } class Response { public Integer status; public Data[] data; public Response(Integer status) { this.status = status; this.data = new List<Data>(); } } class Data { public String id; public String name; public String created; public Data(String id, String name, String created) { this.id = id; this.name = name; this.created = created; } } }
My testclass:
@isTest private class TestOuterClass { static testMethod void testOuterClass() { //Creating test data... Test.startTest(); insert testdata; Test.stopTest(); } }
By doing the same thing pretty much.
May contain typos.
.
All Answers
By doing the same thing pretty much.
May contain typos.
.
Thank you!
So, edited:
My class:
My testclass:
This gives me 100 % coverage.