EasySave and Unit Tests

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
Vincent Abric
Posts: 5
Joined: Mon May 05, 2014 3:32 pm

EasySave and Unit Tests

Post by Vincent Abric »

Hi,

I have developped some Unit Tests for my EasySave implementation, using the unity test tools, but I have some trouble since the 2.43 (2.42 was working well). Each time I call a function from ES2 in a UTest (ES2.Save() for example), a NullReferenceException is thrown.

Thanks
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: EasySave and Unit Tests

Post by Joel »

Hi there,

Firstly, if you haven't already upgraded please upgrade to v2.46.

Secondly, would you be able to post the code that you are using? Does the code work fine outside of UTest?

As we have no affiliation with UTest and as it's not an official Unity feature, I'm afraid we cannot guarantee support for it. If it is a bug with UTest, it is most likely that it doesn't work with functions which use generics, so you would need to ask them to resolve this.

All the best,
Joel
Vincent Abric
Posts: 5
Joined: Mon May 05, 2014 3:32 pm

Re: EasySave and Unit Tests

Post by Vincent Abric »

Hi,

I'm already using the v2.46.

Here's a very simple code that doesn't work. Simply create a .cs in an editor folder then run it using the Unit Test Runner. This code works well outside the utests.

Code: Select all

using NUnit.Framework;

internal class Saving_utest {
	[Test]
	public void Save() {
		ES2.Save(242, "myInt");
	}
}
Thanks for the help.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: EasySave and Unit Tests

Post by Joel »

Thanks for the response,

I'm afraid that because it works outside of UTest, it's a bug at their end so you'll need to talk to them about it (as we have no control over their code).

The only things I can think of that would affect UTest between 2.42 and now is that some of our inner classes and methods are hidden from code completion using the attribute:

Code: Select all

[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
And generics are used slightly differently to conform with the AOT compiler, but there's certainly nothing unusual about our code (it uses absolutely no reflection).

If you send me the full error your getting, or even better, the Log File containing the error, I'll see if I can work out what could be going wrong at their end.

- Joel
Vincent Abric
Posts: 5
Joined: Mon May 05, 2014 3:32 pm

Re: EasySave and Unit Tests

Post by Vincent Abric »

Here's the error I'm getting when running the utest :

Code: Select all

---
System.NullReferenceException : Object reference not set to an instance of an object
---EXCEPTION---
at ES2TypeManager.GetES2Type (System.Type type) [0x00000] in <filename unknown>:0
at ES2Writer.Write[Int32] (Int32 param, System.String tag) [0x00000] in <filename unknown>:0
at ES2.Save[Int32] (Int32 param, System.String identifier) [0x00000] in <filename unknown>:0
at Saving_utest.Save () [0x00000] in C:\vabric-PC\KD-Productions\Mainline\Assets\Source\UnitTests\Editor\Saving\Saving_utest.cs:6
Hope that helps.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: EasySave and Unit Tests

Post by Joel »

It looks like the static constructor which initialises the Type list isn't getting called, which would be a bug at their end (presumably their reflection doesn't account for static constructors).

If this is the case, it won't be difficult to work around it at our end, so I'll remove the need for a static constructor in v2.47 and see if that solves your problem. We hope to have it submitted to the Asset Store for approval by the end of the week.

All the best,
Joel
Vincent Abric
Posts: 5
Joined: Mon May 05, 2014 3:32 pm

Re: EasySave and Unit Tests

Post by Vincent Abric »

Thanks a lot for the help! I'll let you know if this solve the problem.
Vincent Abric
Posts: 5
Joined: Mon May 05, 2014 3:32 pm

Re: EasySave and Unit Tests

Post by Vincent Abric »

Hi,

I found what was causing the problem : Easy Save is not properly initialized when its functions are called from a unit test (ES2Init is not created and its Awake() function is never called).
The workaround I found is to add a the content of the ES2Init.Awake() function in the constructor of the utest class, so the dictionary in ES2TypeManager is correctly filled.

Hope that helps.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: EasySave and Unit Tests

Post by Joel »

Thanks for the heads up Vincent. Hopefully this will be of use to other UTest users!

All the best,
Joel
Locked