# How to unit test Okta Java SDK

**URL:** <https://devforum.okta.com/t/how-to-unit-test-okta-java-sdk/21037>\
**Category:** Questions\
**Created:** [June 21, 2022, 4:53pm UTC](https://devforum.okta.com/t/how-to-unit-test-okta-java-sdk/21037 "2022-06-21T16:53:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjpspf](https://avatars.discourse-cdn.com/v4/letter/t/838e76/32.png) [@tjpspf](https://devforum.okta.com/u/tjpspf)\
**Post date:** [June 21, 2022, 4:53pm UTC](https://devforum.okta.com/t/how-to-unit-test-okta-java-sdk/21037/1 "2022-06-21T16:53:37Z")

</div>

I’m trying to unit test my use of the Okta Java SDK to (1) retrieve User and Group information and (2) map the Okta Java SDK classes/instances to our own User and Group classes.

However, I’m having a hard time figuring out the best way to create dummy/mock test instances of Client, User, Group, List, and List for my unit tests.

I’d love to be able to just instantiate test Users and Groups, set their properties, and then use them in my unit tests. But I’m running into difficulties pulling this off.

Specifically, if I want to create a mock User (and a mock list of Users) for a test, how do I give UserBuilder the Client that it needs to .buildAndCreate(client)? Do I give it a real Client that’s configured with the information for, say, my Okta Developer account? Or can I just give it a mock Client? I’d like to avoid making actual HTTP requests to Okta APIs in my unit tests, if possible.

I’ve read @bdemers answer to a similar question from @hernan_plascencia here: [Spring Boot Okta sdk user creation unit test](https://devforum.okta.com/t/spring-boot-okta-sdk-user-creation-unit-test/6097) But, being a relatively new developer, I could still use a bit more help with this.

---

<div class="post-metadata">

**Author:** ![tjpspf](https://avatars.discourse-cdn.com/v4/letter/t/838e76/32.png) [@tjpspf](https://devforum.okta.com/u/tjpspf)\
**Post date:** [June 28, 2022, 12:57pm UTC](https://devforum.okta.com/t/how-to-unit-test-okta-java-sdk/21037/2 "2022-06-28T12:57:20Z")

</div>

NOTE: “List, and List” is supposed to read `List<User>, and List<Group>`. In my production code, I’m taking Okta Java SDK’s `UserList` and `GroupList` and converting them into `List`s.

---

<div class="post-metadata">

**Author:** ![tjpspf](https://avatars.discourse-cdn.com/v4/letter/t/838e76/32.png) [@tjpspf](https://devforum.okta.com/u/tjpspf)\
**Post date:** [June 28, 2022, 9:06pm UTC](https://devforum.okta.com/t/how-to-unit-test-okta-java-sdk/21037/3 "2022-06-28T21:06:54Z")

</div>

This seems to relate to this “closed” GitHub issue here: [Writing Unit testing for sdk functions · Issue #617 · okta/okta-sdk-java · GitHub](https://github.com/okta/okta-sdk-java/issues/617)

As far as I can tell, no substantive answer/solution has been provided. Am I mistaken?

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [February 12, 2024, 8:03pm UTC](https://devforum.okta.com/t/how-to-unit-test-okta-java-sdk/21037/4 "2024-02-12T20:03:45Z")

</div>


