If they are internal
functions you can inherit them and test them, if they are private
functions, I believe the only way to unit test them is to make them public
/internal
, test them and then change them back to private once the tests are passing.
Another way to go about it would be to refactor your code so that the private functions are part of a library
that you import into the contract
. That way the functions are public
in the library
but not exposed in the actual contract
.
Your lucky day (had to solve this few days ago):
See that you have truffle-core
locally in your project. If not, do:
npm install truffle-core
Then use a configuration similar to this: ( Debug -> Open Configurations )
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "truffle test (debugable)",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}\\node_modules/truffle-core/cli.js",
"args": [
"test"
]
}
]
}
Or add a new one (simple "node" launch, then edit it)
If your code does not spawn another node process (brings trouble which are essentially an node.js bug), you should be good.
Best Answer
Add the following to your configurations in
launch.json
:You will need to adjust the
program
property to match the path of your installed truffle if you have installed truffle globally.