Anybody got a tutorial or some knowledge on how to test a component and interact with it in the repl?
Or is the idea to test the system as a whole and the components will get tested as the system gets tested?
Currently the only way in my system is through HTTP and MQTT.
in the repl, just start the component: (def db-component-instance (component/start my-component))
then you can use that in the repl.
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.
@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…?
Just what is best practice, Test the Components vs Test the system’s surface
@seancorfield I coudnt find the docs. I see very little on the github readme about testing
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.
In general you’re going to be testing functions that depend on components (i.e., take components as arguments).
So you don’t really “test the component”, except insofar as you can test that it starts / stops correctly.
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.
Does that help? If not, can you be more precise about what you’re asking…?
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.