# \[SOLVED\] Can't understand how to generate test mock

**URL:** <https://community.apollographql.com/t/solved-cant-understand-how-to-generate-test-mock/6385>\
**Category:** Client SDKs\
**Tags:** client, mobile, ios\
**Created:** [June 22, 2023, 9:47am UTC](https://community.apollographql.com/t/solved-cant-understand-how-to-generate-test-mock/6385 "2023-06-22T09:47:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Mallard](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/paul_mallard/32/4367_2.png) [@Paul\_Mallard](https://community.apollographql.com/u/Paul_Mallard)\
**Post date:** [June 22, 2023, 9:47am UTC](https://community.apollographql.com/t/solved-cant-understand-how-to-generate-test-mock/6385/1 "2023-06-22T09:47:25Z")

</div>

Hi, i’m trying to generate the tests mocks, using Apollo in order to write a few unit tests for my app, i just can’t understand how to setup my project in order to be able to do this, i added a screenshot from my apollo-codegen-config.json.  
When i try to generate my files without filling the testMocks section it work perfectly fine but when i’m adding the SPM section and the targetName i got this error :  
Error: typeMismatch(ApolloCodegenLib.ApolloCodegenConfiguration.TestMockFileOutput, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: “output”, intValue: nil), CodingKeys(stringValue: “testMocks”, intValue: nil)], debugDescription: “Invalid number of keys found, expected one.”, underlyingError: nil))

 ![CleanShot 2023-06-22 at 10.52.19@2x](https://us1.discourse-cdn.com/flex019/uploads/apollographql/original/2X/5/5f136243da1fd1830fe189face80f6c9d1e3f320.jpeg)

---

<div class="post-metadata">

**Author:** ![ZachF-Apollo](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/zachf-apollo/32/4210_2.png) [@ZachF-Apollo](https://community.apollographql.com/u/ZachF-Apollo)\
**Post date:** [June 22, 2023, 1:03pm UTC](https://community.apollographql.com/t/solved-cant-understand-how-to-generate-test-mock/6385/2 "2023-06-22T13:03:16Z")

</div>

The key for your test mocks should be `swiftPackage` not `swiftPackageManager`, like this:

```auto
"testMocks" : {
      "swiftPackage" : {
          "targetName": "MockApollo"
      }
 }

```

Your `moduleType` under `schemaTypes` must also be set to `swiftPackageManager` for this to work. You can read more about this in the documentation [here](https://www.apollographql.com/docs/ios/code-generation/codegen-configuration#test-mocks-in-a-swift-package).

---

<div class="post-metadata">

**Author:** ![Paul\_Mallard](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/paul_mallard/32/4367_2.png) [@Paul\_Mallard](https://community.apollographql.com/u/Paul_Mallard)\
**Post date:** [June 22, 2023, 2:34pm UTC](https://community.apollographql.com/t/solved-cant-understand-how-to-generate-test-mock/6385/3 "2023-06-22T14:34:51Z")

</div>

Thank you so much man, it’s working now  
True Hero

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:48pm UTC](https://community.apollographql.com/t/solved-cant-understand-how-to-generate-test-mock/6385/4 "2025-02-06T20:48:46Z")

</div>


