# How to print to screen in unit tests?

**URL:** <https://swi-prolog.discourse.group/t/how-to-print-to-screen-in-unit-tests/6347>\
**Category:** General\
**Created:** [March 6, 2023, 12:46pm UTC](https://swi-prolog.discourse.group/t/how-to-print-to-screen-in-unit-tests/6347 "2023-03-06T12:46:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![heiheshang](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/heiheshang/32/4419_2.png) [@heiheshang](https://swi-prolog.discourse.group/u/heiheshang)\
**Post date:** [March 6, 2023, 12:46pm UTC](https://swi-prolog.discourse.group/t/how-to-print-to-screen-in-unit-tests/6347/1 "2023-03-06T12:46:48Z")

</div>

Why is this code not displaying anything on the screen?

```prolog
  debug(log, 'sum ~q', [Sum]),

```

---

<div class="post-metadata">

**Author:** ![jamesnvc](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jamesnvc/32/14_2.png) [@jamesnvc](https://swi-prolog.discourse.group/u/jamesnvc)\
**Post date:** [March 6, 2023, 2:07pm UTC](https://swi-prolog.discourse.group/t/how-to-print-to-screen-in-unit-tests/6347/2 "2023-03-06T14:07:36Z")

</div>

debug/3 will only show messages if you’ve turned the “topic” on; have you run `debug(log).` first?

---

<div class="post-metadata">

**Author:** ![heiheshang](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/heiheshang/32/4419_2.png) [@heiheshang](https://swi-prolog.discourse.group/u/heiheshang)\
**Post date:** [March 6, 2023, 2:15pm UTC](https://swi-prolog.discourse.group/t/how-to-print-to-screen-in-unit-tests/6347/3 "2023-03-06T14:15:41Z")

</div>

:- use\_module(library(debug)).

:- debug(log).

---

<div class="post-metadata">

**Author:** ![jamesnvc](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jamesnvc/32/14_2.png) [@jamesnvc](https://swi-prolog.discourse.group/u/jamesnvc)\
**Post date:** [March 6, 2023, 2:23pm UTC](https://swi-prolog.discourse.group/t/how-to-print-to-screen-in-unit-tests/6347/4 "2023-03-06T14:23:29Z")

</div>

Strange. I [just recently](https://swi-prolog.discourse.group/t/setting-user-error-for-a-thread-pool/6341) had an issue where debug calls in a thread that was created with `user_error` pointing elsewhere wouldn’t show up. How is the predicate containing that debug being run?

Something I ended up doing to make it show up:

```prolog
?- stream_property(S, alias(user_error)), debug(log > S)

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [March 6, 2023, 2:45pm UTC](https://swi-prolog.discourse.group/t/how-to-print-to-screen-in-unit-tests/6347/5 "2023-03-06T14:45:34Z")

</div>

The version of plunit in the development versions by default suppresses output for test that succeed. The test framework captures the output and discards it if the test succeeds. You can get the “old” behavior using

```
?- set_prolog_flag(plunit_output, always).

```

The stable (9.0.x) always prints output.

Further, when using optimization (`-O` or the Prolog flag), debug/3 statements are removed by the compiler.

---

<div class="post-metadata">

**Author:** ![heiheshang](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/heiheshang/32/4419_2.png) [@heiheshang](https://swi-prolog.discourse.group/u/heiheshang)\
**Post date:** [March 7, 2023, 1:18am UTC](https://swi-prolog.discourse.group/t/how-to-print-to-screen-in-unit-tests/6347/6 "2023-03-07T01:18:31Z")

</div>

it didn’t help me
