The type initializer for 'ReactiveUI.CreatesCommandBindingViaEvent' threw an exception.
I'm getting this error when running nunit tests on mac.
System.TypeInitializationException : The type initializer for 'ReactiveUI.RxApp' threw an exception. ----> System.TypeInitializationException : The type initializer for 'ReactiveUI.CreatesCommandBindingViaEvent' threw an exception.
[Test]
public void Fails()
{
(new TestScheduler()).With(sched => {});
}
or
[Test]
public void Fails()
{
TestUtils.WithScheduler(new TestScheduler());
}
packages.config
...
<package id="reactiveui" version="7.0.0" targetFramework="net45" />
<package id="reactiveui-core" version="7.0.0" targetFramework="net45" />
<package id="reactiveui-testing" version="7.0.0" targetFramework="net45" />
<package id="Rx-Testing" version="2.2.5" targetFramework="net45" />
...
Ah ok so in unit test this is the line that throws exception, so am i missing some initialization for unit tests ?
var scheduler = RxApp.MainThreadScheduler;
stackTrace " at ReactiveUI.Registrations+<>c.1[TResult] f, System.Type t) [0x00000] in <d13e35ba0bd44f5faf701228ab8b1d28>:0 \n at ReactiveUI.Registrations.Register (System.Action2[T1,T2] registerFunction) [0x00149] in
What sort of class library is the unit test located in?
- net45?
- mac45?
- pclprofile¿?
Can you please gist up the unit test csproj
https://gist.github.com/inyman/ebc654f129b2eda0e00770a98218eeca
Thanks for quick response btw
Any ideas what I'm doing wrong ?
Not sure
your Splat version looks older maybe that's causing problems? Update it to 1.6.2?
I tried a quick NUNIT project against .net45 here https://github.com/PureWeen/RxUI7NunitNET45
and it seems to run fine
Maybe enable first chance exceptions as well see if that reveals more things?
I checked out your project and still fails for me. Running inside xamarin studio
I'm not really sure then when I run it in xamarin studio it compiles and passes for me just fine
Maybe something is messed up with your nuget cache of packages?
http://stackoverflow.com/questions/30933277/how-to-clear-nuget-package-cache-using-command-line
Hm still no luck, you're using mac ?
Looks like this is throwing exception Locator.CurrentMutable.InitializeReactiveUI();
ok works on windows for me as well, would be cool to figure out what's the problem with mac
My guess with that would be from it being net45 so it's not going to load on iOS. Like I'm assuming the ReactiveUI net45 dll is full framework net45 which isn't going to be able to bootstrap up into iOS...
hm could i target some other framework ?
Yea most likely. Personally I haven't done a lot with unit tests in the context of iOS but if you look at the RxUI source there's an iOS based test project against xUnit. If you just create an iOS class library that might possibly do what you need. The ReactiveUI iOS test project looks to just be a class library that targest Xarmin iOS. I've only ever really ran unit tests in a windows environment and then I just use the Xamarin UI Test features to run UI tests through the emulator or against devices... It'd probably be more correct for me to run the tests all the places :-) but just haven't really
Hm. Going without TDD any further is not an option for me. So either i switch to Windows (not likely) or i find a way to test it or switch to some other lib (if any)
Well that's not really what I was referring to just that I hadn't done it on iOS before.. The ReactiveUI source runs TDD against iOS. If you grab the source you'll see the project there. I've never messed with it but I'm assuming it works and runs on iOS :-) . If you create a Xamarin iOS library I'm sure you'll be able to add Xamarin iOS libraries to it plus a Xamarin iOS compatible TDD FW and it'll work.
Extracted logic that's executed within observable to protected method and i unit test that for now , tried mono mac, ios lib, changing csproj to Xamarin.Mac20 etc etc nothing worked so this is good for now.
I think this is the same issue as this one
https://github.com/reactiveui/ReactiveUI/issues/780
I have exactly the same issue. I tried :
- Create a Xamarin.Mac library and add the Nunit test there. Switch the ReactiveUI and Splat to Xamarin.Mac20 and MonoMac.
- Create a Xamarin.Ios library and add the Nunit test there. Switch the ReactiveUI and Splat to Xamarin.ios10 and monotouch.
- Create a normal Nunit Xamarin lib Switch the ReactiveUI and Splat to Xamarin.Mac20 and MonoMac.
Also tried with net45 as path but nothing seems to works. It's also a big issue for us as we really need Unit Tests. If we cannot find a way to make it work we will need to swicth to an other library for our bindings. It's sad, we really like the way ReactiveUI is putting everything togheter.
Hope someone will be able to help us.Thanks in advance.
@Amnysia if you're testing domain logic outside ui i went for this approach until its fixed
protected override IObservable<Game> BuildUseCaseObservable(object[] args) {
return Observable.Create<Game>(async observer => {
Game newGame = await ExecuteUseCase();
observer.OnNext(newGame);
observer.OnCompleted();
return Disposable.Empty;
});
}
internal async System.Threading.Tasks.Task<Game> ExecuteUseCase() {
}
My unit tests are testing ExecuteUseCase logic , maybe this helps
With iOS have you tried the Xamarin Unit Test template projects? Or are you just running it straight from a class library?
I'm pretty sure the iOS tests have to be ran from inside a simulator which is what they do here https://developer.xamarin.com/guides/ios/deployment,_testing,_and_metrics/touch.unit/
Which should then let you run specific tests
I'd test it out more but the latest Xamarin release to iOS seems to have horked my setup on there :-(
Alright i had to set Link to Link SDK only and now I'm back to working
But yea.. If you use the link I posted above then you can run unit tests. Basically it creates a little iOS app test runner and then you can kick off the tests inside the simulator
I'm not sure if there's an easier way to make it work on the iOS side of things :-/ I'm thinking once RxUI gets all updated to netstandard and nunit 3.5 gets better integration with xam studio then maybe you'll be able to just run those from a simple test runner.