# How to properly unit test XBlock views

**URL:** <https://discuss.openedx.org/t/how-to-properly-unit-test-xblock-views/12656>\
**Category:** Development\
**Tags:** devstack, xblock\
**Created:** [March 28, 2024, 8:22pm UTC](https://discuss.openedx.org/t/how-to-properly-unit-test-xblock-views/12656 "2024-03-28T20:22:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsprenkle](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/nsprenkle/32/304_2.png) [@nsprenkle](https://discuss.openedx.org/u/nsprenkle)\
**Post date:** [March 28, 2024, 8:22pm UTC](https://discuss.openedx.org/t/how-to-properly-unit-test-xblock-views/12656/1 "2024-03-28T20:22:18Z")

</div>

I’ve been working on a new XBlock and I have it working when installed into LMS / CMS. However, I’m getting hung up on how to create good unit tests for the XBlock views (e.g. `student_view`).

The only example I’ve been able to find that actually unit-tests views is [edx-ora2](https://github.com/openedx/edx-ora2), but this is somehow able to import `workbench` and `scenario` and other helpers from the xblock-sdk that I am unable to get set up for this XBlock. (Consistently running into the `no module found "Workbench"` error when I try to do any reference here in my tests, even after installing `xblock-sdk` dependency.

Any tips / resources would be amazing, I’m definitely getting stuck here.

---

<div class="post-metadata">

**Author:** ![braden](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/braden/32/46_2.png) [@braden](https://discuss.openedx.org/u/braden)\
**Post date:** [March 28, 2024, 9:32pm UTC](https://discuss.openedx.org/t/how-to-properly-unit-test-xblock-views/12656/2 "2024-03-28T21:32:18Z")

</div>

What you are describing sounds more like integration tests, because they are running using the “workbench” runtime, which is a full XBlock runtime.

There is [`SeleniumXBlockTest`](https://github.com/openedx-unsupported/xblock-utils/blob/7a88cb9b5cc56ff6b23f6ffcb320667b1ea27e92/xblockutils/base_test.py#L33) which is now deprecated and unmaintained, but some XBlocks still use it to run integration tests in the workbench, e.g. xblock-poll: [xblock-poll/tests/integration at master · open-craft/xblock-poll · GitHub](https://github.com/open-craft/xblock-poll/tree/master/tests/integration)

Closer to unit tests are what Drag and Drop does: [xblock-drag-and-drop-v2/tests/utils.py at master · openedx/xblock-drag-and-drop-v2 · GitHub](https://github.com/openedx/xblock-drag-and-drop-v2/blob/master/tests/utils.py) - it still uses the workbench runtime but pretty minimally, I think; most stuff is mocked out so it focuses on the code from the XBlock itself.

Both of these repos use GitHub Actions CI so you should definitely be able to use one of those approaches for any new XBlocks.

In the future, I think a much better approach is needed, either by being able to test XBlocks simply by installing XBlock + [Learning Core](https://github.com/openedx/openedx-learning/), or by migrating to [a successor to XBlocks](https://docs.google.com/document/d/1btnE7pIZccvlrDrJ8gHjEPfOrkMCZgSkgw8D9jXaLx4/edit#heading=h.90apnqnmcp86) that has a much more well-defined API and test infrastructure.
