# How to use foundationdb unit test?

**URL:** <https://forums.foundationdb.org/t/how-to-use-foundationdb-unit-test/3077>\
**Category:** Development\
**Created:** [December 15, 2021, 11:13am UTC](https://forums.foundationdb.org/t/how-to-use-foundationdb-unit-test/3077 "2021-12-15T11:13:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![superhail](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/superhail/32/1191_2.png) [@superhail](https://forums.foundationdb.org/u/superhail)\
**Post date:** [December 15, 2021, 11:13am UTC](https://forums.foundationdb.org/t/how-to-use-foundationdb-unit-test/3077/1 "2021-12-15T11:13:48Z")

</div>

I noticed that there are some unit tests in foundationdb’s source code([link](https://github.com/apple/foundationdb/blob/a9b9f786a78e08d388ff72e07f4d158be9172663/flow/Platform.cpp#L3618)), but I do not know how to run them, could someone please give me some advice on how to build and run them? Thanks in advance

---

<div class="post-metadata">

**Author:** ![SteavedHams](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/steavedhams/32/18_2.png) [@SteavedHams](https://forums.foundationdb.org/u/SteavedHams)\
**Post date:** [December 19, 2021, 9:06am UTC](https://forums.foundationdb.org/t/how-to-use-foundationdb-unit-test/3077/2 "2021-12-19T09:06:00Z")

</div>

Unit tests can be run in simulation via

```auto
fdbserver -r simulation -f <specfile> [-s <randomseed>] [-b <on|off>]

```

where a spec file invokes the `UnitTests` workload with a prefix pattern to match against unit test names to determine the set of tests to run. The spec file can also pass test parameters, one per line, with the same `name=value` syntax as the `testsMatching` line which populates the `params` object that is available within the scope of a unit test.

This file serves as a template for running a specific unit test:

> <https://github.com/apple/foundationdb/blob/master/tests/SpecificUnitTest.txt>

In FDB 7.0 there is also a faster path to running unit tests in normal, non-simulation mode, which is

```auto
fdbserver -r unittests -f <prefixPattern> [--test_param name=value]...

```

such as

```auto
fdbserver -r unittests -f /status/json/builder

```

---

<div class="post-metadata">

**Author:** ![superhail](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/superhail/32/1191_2.png) [@superhail](https://forums.foundationdb.org/u/superhail)\
**Post date:** [December 20, 2021, 1:26pm UTC](https://forums.foundationdb.org/t/how-to-use-foundationdb-unit-test/3077/3 "2021-12-20T13:26:29Z")

</div>

@SteavedHams man, I build my fdb based on commit\_id `d183b0c7c`, and when I run the command `./bin/fdbserver -r unittests -f /status/json/builder`, it just returned `ERROR: Unknown role 'unittests'`

---

<div class="post-metadata">

**Author:** ![SteavedHams](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/steavedhams/32/18_2.png) [@SteavedHams](https://forums.foundationdb.org/u/SteavedHams)\
**Post date:** [December 20, 2021, 5:01pm UTC](https://forums.foundationdb.org/t/how-to-use-foundationdb-unit-test/3077/4 "2021-12-20T17:01:43Z")

</div>

My apologies, the `-r unittests` method is new for FDB 7.0, prior to that you must use the other method.

---

<div class="post-metadata">

**Author:** ![superhail](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/superhail/32/1191_2.png) [@superhail](https://forums.foundationdb.org/u/superhail)\
**Post date:** [December 21, 2021, 2:04am UTC](https://forums.foundationdb.org/t/how-to-use-foundationdb-unit-test/3077/5 "2021-12-21T02:04:57Z")

</div>

I would be grateful if u can tell me where is the documentation about “the other method”, because I really cant find it 😥

---

<div class="post-metadata">

**Author:** ![SteavedHams](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/steavedhams/32/18_2.png) [@SteavedHams](https://forums.foundationdb.org/u/SteavedHams)\
**Post date:** [December 21, 2021, 4:08am UTC](https://forums.foundationdb.org/t/how-to-use-foundationdb-unit-test/3077/6 "2021-12-21T04:08:54Z")

</div>

My post above had 2 usage forms, you tried the second one at the end of the post. You’ll have to use the first one, from the beginning of the post.

> [@SteavedHams](#):
>
> ```auto
> fdbserver -r simulation -f <specfile> [-s <randomseed>] [-b <on|off>]
> 
> ```

---

<div class="post-metadata">

**Author:** ![superhail](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/superhail/32/1191_2.png) [@superhail](https://forums.foundationdb.org/u/superhail)\
**Post date:** [December 21, 2021, 12:31pm UTC](https://forums.foundationdb.org/t/how-to-use-foundationdb-unit-test/3077/7 "2021-12-21T12:31:00Z")

</div>

thx a lot, so before version 7.0 there is no way to test without simulation, right?

---

<div class="post-metadata">

**Author:** ![SteavedHams](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/steavedhams/32/18_2.png) [@SteavedHams](https://forums.foundationdb.org/u/SteavedHams)\
**Post date:** [December 21, 2021, 4:39pm UTC](https://forums.foundationdb.org/t/how-to-use-foundationdb-unit-test/3077/8 "2021-12-21T16:39:16Z")

</div>

There actually is, but there are some quirks to it. You can use `-r test` instead of `-r simulation` along with `-f <specfile>`, but this mode requires a cluster file because it assumes the test is executing a workload against a live cluster. Even if the test spec says `useDB = no` a cluster file will still be required. Since most unit tests do not use a cluster, you can just pass a dummy cluster file with contents such as `1:1@1.1.1.1:1`.

---

<div class="post-metadata">

**Author:** ![osamarin](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/osamarin/32/905_2.png) [@osamarin](https://forums.foundationdb.org/u/osamarin)\
**Post date:** [June 7, 2023, 2:03pm UTC](https://forums.foundationdb.org/t/how-to-use-foundationdb-unit-test/3077/9 "2023-06-07T14:03:05Z")

</div>

Is there a way to run the same simulation repeatelly (with different seeds), until it fails?
