Fork me on GitHub
#component
<
2016-10-27
>
tetriscodes18:10:12

Anybody got a tutorial or some knowledge on how to test a component and interact with it in the repl?

tetriscodes18:10:32

Or is the idea to test the system as a whole and the components will get tested as the system gets tested?

tetriscodes18:10:26

Currently the only way in my system is through HTTP and MQTT.

roberto18:10:13

in the repl, just start the component: (def db-component-instance (component/start my-component))

roberto18:10:34

then you can use that in the repl.

roberto18:10:14

there is nothing special you need to do to test them, other than just start them and pass it to the function that needs to use it.

seancorfield20:10:44

@tetriscodes You can create (and test) any individual component in the REPL (and the Component docs give examples). Not quite sure what you’re asking…?

tetriscodes20:10:39

Just what is best practice, Test the Components vs Test the system’s surface

tetriscodes20:10:39

@seancorfield I coudnt find the docs. I see very little on the github readme about testing

seancorfield20:10:49

So much is going to depend on what the component actually is. Mostly, components are just some data / state with initialization (and possibly termination) code.

seancorfield20:10:14

In general you’re going to be testing functions that depend on components (i.e., take components as arguments).

seancorfield20:10:44

So you don’t really “test the component”, except insofar as you can test that it starts / stops correctly.

seancorfield20:10:24

The docs for Component say that you don’t pass the entire system around everywhere in your code, only the subcomponents that are needed by a particular set of functions. When you’re testing those functions, you only need the subcomponent so you can create just that part with system-map sometimes, or the “constructor” function for the record that has your start/stop functionality.

seancorfield20:10:54

Does that help? If not, can you be more precise about what you’re asking…?

roberto20:10:41

for example, how would you test a database connection in another programming language? You don’t really, at least I have never done that. In component, you might have a Database component that holds a connection (or pool of connections) to a database that other parts of your system depend on to communicate with the database. If I felt the need to test a Database component, for example, I would probably just inspect its properties to see if a connection was open, and then close it and verify that it was closed. There really isn’t much to test. The other way, which is probably done more than once through out the system, is to only test those functions that depend on the database component.