0

While i was writing unit test(NUnit) for wpf application. Got an error 'object reference not set to an instance'

at the bottom level i can see the line which raise exception

 Application.Current.Dispatcher.Invoke(DispatcherPriority.Send,
          new Action(() => loc.ResolveLocalizedValue(out ui)));

this code is used in helper class library. Thanks in advance. Guys please suggest how can i resolve this.

1 Answer 1

2

Application.Current will be null in your case. It returns application object for the current AppDomain which gets set only when application is run.

Test cases are to test business logic i.e. to test ViewModel layer. Code which you want to test should not contain any reference to UI component.


More details can be found here - Application.Current is null in unit test cases. Workaround is provided in the link but I strongly discourage the use of Application.Current in your testcases or usage of it in ViewModel layer which needs to be unit tested.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.