# Journal: Property-Based Testing with PropEr, Erlang, and Elixir

**URL:** <https://forum.devtalk.com/t/journal-property-based-testing-with-proper-erlang-and-elixir/10607>\
**Category:** Journals & Book Clubs\
**Tags:** book-property-based-testing-with-proper-erlang-and-elixir, journal\
**Created:** [17 June 2021 10:04 UTC](https://forum.devtalk.com/t/journal-property-based-testing-with-proper-erlang-and-elixir/10607 "2021-06-17T10:04:12Z")\
**Posts on this page:** 1\
**Showing post:** 26

<div class="post-metadata">

**Author:** ![rustkas](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rustkas/32/2933_2.png) [@rustkas](https://forum.devtalk.com/u/rustkas)\
**Post date:** [25 June 2021 10:01 UTC](https://forum.devtalk.com/t/journal-property-based-testing-with-proper-erlang-and-elixir/10607/26 "2021-06-25T10:01:54Z")

</div>

`Erlang`  
(page 127)  
`test/prop_generators.erl`  
**Question 6** is the most difficult task that I have encountered while reading the book (So far I have read only the first 4 chapters several times.).

The first difficulty - for the input parameter of the generator,

```auto
file(Name) ->
    ?SIZED(
       Size,
       lines(Size, {'$call', ?MODULE, file_open, [Name, [read,write,raw]]})
    ).

```

it requires the name (path) of the file (path to the file). It must be implemented in some way (the author is silent on how to do this, since this is not a significant part of the question). The complexity is compounded by the fact that creating a path to a file (temporary file) in itself is not such an easy task.

I solved the generation of a temporary file using the following functions:

```auto
mktemp() ->
    mktemp("tmp").

-spec mktemp(Prefix) -> Result
   when Prefix :: string(),
        Result :: TempFile :: file:filename().
		
mktemp(Prefix) ->
    Rand = integer_to_list(binary:decode_unsigned(crypto:strong_rand_bytes(8)), 36),
	TempDir = filename:basedir(user_cache, Prefix),
	os:cmd("mkdir " ++ "\"" ++ TempDir ++ "\""),
			
	TempFilePath = filename:join(TempDir, Rand),
	TempFilePath.

```

and implement property based test of their functions [Project source code](https://github.com/rustkas/Property-Based-Testing-with-PropEr-Erlang-and-Elixir-conding-experience/tree/main/code/ch04/exercises/ex06_file_generator).

Then I tried using the suggested generator `file/1`. When starting the test,

```auto
rebar3 proper -m prop_solutions -p prop_make_tmp_file -n 1

```

I noticed that _Automated Symbolic Call_ do not work:

```auto
===>
0/1 properties passed, 1 failed
===> Failed test cases:
prop_solutions:prop_make_tmp_file() -> {'EXIT',
                                        {undef,
                                         [{prop_solutions,file_open,
                                           [".../AppData/Local/tmp/Cache/15U3A5WBAWWOS",

```

This means that when trying to call a function `file_open`, it is not in the expected place. Very strange. 🤨

[Replaced](https://github.com/rustkas/Property-Based-Testing-with-PropEr-Erlang-and-Elixir-conding-experience/tree/main/code/ch04/exercises/ex06_symbolic_call) _Automated Symbolic Call_ with _Symbolic Call_ this error has been corrected.

```auto
===> Testing prop_solutions:prop_make_tmp_file()
.
OK: Passed 1 test(s).
===>
1/1 properties passed

```

So, I will continue my research work. I hoped that I had find solutions and everything will work correctly.

Unfortunately, this did not lead to the desired result - the created temporary file does not contain anything. I tested this by introducing the logging function `io:format` and also directly checked what the files were inside.

That functions that should be called using _Symbolic Call_ are not called all the way.

Also I noticed that the compiler does not perceive symbolic function calls as using them. To prevent the compiler from printing warning messages - I added an extra line to the beginning of the test code file.

```auto
-compile([{nowarn_unused_function, [{ file_open, 2}, {file_write, 2}]}]).

```

* * *

So, I will continue my research work with this functionality (look at [PropEr documentation](https://proper-testing.github.io/apidocs/)). I hope that I will find solutions and everything will work correctly and predictable.

---

_[View the full topic](https://forum.devtalk.com/t/journal-property-based-testing-with-proper-erlang-and-elixir/10607)._
