Dune what is the difference between library and tests stanza?

In the writing and running tests section of the dune docs. For ppx_inline_test the following stanza is suggested.

(library
 (name foo)
 (preprocess (pps ppx_inline_test)))

However, I’ve also encountered the following example in the stanza reference section of the docs

(tests
 (names mytest expect_test)
 <optional fields>)

I’m curious what the difference is? How would I know when to use libraries or tests?

Welcome !
One of them declares a library, and activate a test ppx in that library.
That ppx is a syntax extension that allows you to declare inline tests. It is documented here : GitHub - janestreet/ppx_inline_test: Syntax extension for writing in-line tests in ocaml code.
The other is more flexible and does not assume you use a particular syntax extension to declare your tests. I do not know how to use it, but it is documented.