Closed luttje closed 1 year ago
I imagine writing tests in annotations and creating a Build Script which will generate a Lua test file for me. That way I can easily write new tests as I think them up, near where I'm already writing code anyway:
public class MongoClient : LuaMetaObjectBinding, IDisposable
{
// ...
#region Tests
[LuaTest("client = MongoClient('mongodb://etc...')")]
[LuaTest("assert(type(client) == 'MongoClient', 'Constructed object is not of the correct type!')")]
[LuaTest("assert(etc..., 'Error!'")]
[LuaTest("assert(etc..., 'Error!'")]
[LuaTest("assert(etc..., 'Error!'")]
[LuaTest("assert(etc..., 'Error!'")]
[LuaTest("assert(etc..., 'Error!'")]
#endregion
[LuaStatic(IsInitializer = true)]
public static MongoClient Constructor(ILua lua, string connectionString)
{
// ...
}
#region Tests
[LuaTest("client.DropDatabase('testdb')")]
[LuaTest("assert(client.GetDatabaseNames().IndexOf('testdb') == -1, 'Database was not removed!'")]
[LuaTest("assert(etc..., 'Error!'")]
[LuaTest("assert(etc..., 'Error!'")]
[LuaTest("assert(etc..., 'Error!'")]
[LuaTest("assert(etc..., 'Error!'")]
[LuaTest("assert(etc..., 'Error!'")]
#endregion
[LuaMethod]
public void DropDatabase(string name)
=> client.DropDatabase(name);
I'll sleep on it.
Take the time to write unit tests.
Consider using the Gmod.NET Tests Project as an example.
The Gmod.NET workflow is also informative. Apparently github can even download Garry's mod and run the tests: