EasySave and Unit Tests
-
- Posts: 5
- Joined: Mon May 05, 2014 3:32 pm
EasySave and Unit Tests
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
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
Re: EasySave and Unit Tests
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
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
-
- Posts: 5
- Joined: Mon May 05, 2014 3:32 pm
Re: EasySave and Unit Tests
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.
Thanks for the help.
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");
}
}
Re: EasySave and Unit Tests
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:
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
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)]
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
-
- Posts: 5
- Joined: Mon May 05, 2014 3:32 pm
Re: EasySave and Unit Tests
Here's the error I'm getting when running the utest :
Hope that helps.
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
Re: EasySave and Unit Tests
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
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
-
- Posts: 5
- Joined: Mon May 05, 2014 3:32 pm
Re: EasySave and Unit Tests
Thanks a lot for the help! I'll let you know if this solve the problem.
-
- Posts: 5
- Joined: Mon May 05, 2014 3:32 pm
Re: EasySave and Unit Tests
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.
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.
Re: EasySave and Unit Tests
Thanks for the heads up Vincent. Hopefully this will be of use to other UTest users!
All the best,
Joel
All the best,
Joel