photo

Unit testing

Recommended Posts

I have developed one game with Unity on hobby basis, and also done some testing in Godot, but I have 20 years of experience with software development (started with c++ and now later mainly c#).

I was wondering what the recommended way to work with Unigine and unit testing is. It looks like it might not be possible to create a library (or a test project) and include unigine libraries. One of the things I would like to do is e.g. to build some meshes programmatically, for this it would be really nice to be able to build a library and use a test project tests for generated meshes (vector math, rotating, translating points etc).

I like the API, the documentation and I really love the physics capabilities. I have some thoughts about improvements for the editor, but it may be that I just don't know it well enough yet, so I will get back to this.

Share this post


Link to post

I would really appreciate some feedback on this. It would be great to be able to unit test logic connected to vec3, MathLib etc.

This is the error I get when I try to use Unigine methods in a c# unit test project using NUnit. And when I try to add reference to missing module, it looks like it is not supported.
image.thumb.png.bbb8c421c512d409593668e0c2ffc871.png

Share this post


Link to post

Sorry for being silent in this thread. We have no experience with NUnit and can't suggest anything at this point. Maybe, if you could have sent us the test project we'll dig a bit deeper, but I can't promise we'll get a result fast. Team is approaching pre-release stage and everyone will be consumed with burning tasks next month.

Share this post


Link to post

Hi, I have included a very simple csproj where NUnit nuget is used. The reference to Unigine must be updated.

I really hope that it will be possible somehow to use Unigine libraries in a unit test context. Please let me know if there is anything I can do to help or explain what I want to do.

Thank you, and good look with the work on next release.

 

UnitTests.zip

Share this post


Link to post

bentaudun

Thanks for the example. What I did in my tests:

  1. Created a new C# (.NET Core project) with 2.12.0.2 SDK;
  2. Opened generated unigine_project.csproj and added following lines:
    <ItemGroup>
         <PackageReference Include="nunit" Version="3.12.0" />
         <PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
         <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
    </ItemGroup>
  3. Loaded solution and in main.cs I've used following code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using Unigine;
    using NUnit.Framework;
    
    namespace UnigineApp
    {
    	class UnigineApp
    	{
    
    		[SetUp]
    		public void Setup()
    		{
    		}
    
    		[Test]
    		static public void Test1()
    		{
    			// not a very interesting test, but the idea is that tests can be made
    			// to check for example logic to generate geometry, meshes etc
    			// modify csproj file to point to valid location for UnigineSharpCore_x64.dll
    
    			ivec3 v1 = new ivec3(1, 0, 0);
    			ivec3 v2 = new ivec3(0, 1, 0);
    
    			MathLib.Cross(out ivec3 cross, v1, v2);
    
    			Assert.AreEqual(0, cross.x);
    			Assert.AreEqual(0, cross.x);
    			Assert.AreEqual(0, cross.z); // triggering the assert
    
    			Log.Message("I'm here\n");
    		}
    
    		[STAThread]
    		static void Main(string[] args)
    		{
    			Engine.Init(args);
    			Test1();
    
    		}
    	}
    }

     

It triggers the assertion on startup (when I hit F5 in Visual Studio):
image.png

You need to init the Engine in order to use API.

Is that what you are looking for?

Thanks!

 

unigine_project_1.zip

Share this post


Link to post

Thank you for looking into this. From what you explain here, it sounds like everything needs to run with the Unigine engine initialized. As far as I can tell this requires specific setup, a 'data' directory with configs ++.

Ideally it should be possible to use e.g. the MathLib methods, vec3, quat and things that perhaps don't depend on the graphics engine, to test code logic for creating geometry. 

The [Test] attribute in NUnit marks a method that will be run during unit testing. Such tests can be run from IDEs (like Visual Studio or Rider), or they can be run as part of automated builds.

Share this post


Link to post

If you don't have any GPU on your build server you can pass -video_app null to the start-up parameters (in that case engine will use the CPU-only logic only and no windows will be created).

Share this post


Link to post