• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
2
Question by LavaPatrik · Mar 31, 2017 at 06:43 PM · exceptiontestingexpected

(5.6) NUnit's ExpectedException Attribute is gone?

I just upgraded to Unity 5.6, and to my surprise a ton of my unit tests no longer compiles. It looks as if the ExpectedException attribute can no longer be found.

 error CS0246: The type or namespace name `ExpectedException' could not be found. Are you missing an assembly reference?

This is not only affecting my project, but some of my (more well tested) purchased plugins as well. I've gone through the change log for 5.6, but I can't find any changes whatsoever to NUnit or the test runner.

Whats going on?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Nerull22 · Mar 31, 2017 at 11:42 PM

In Unity 5.6 they updated to NUnit 3. And in NUnit 3, they decided to remove this attribute. They claim th at instead of having an attribute that expects an exception, that it should be a separately written unit test. I don't know if I necessarily agree with the decision, but this is what you're seeing.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image LavaPatrik · Apr 01, 2017 at 05:42 AM 0
Share

You're right, they have updated to NUnit 3. Where did you get that information by the way? I can't remember reading it anywhere, and it would have been useful to know.

The solution is using the Throws functionality ins$$anonymous$$d.

 Assert.That(()=> new SomethingThatCantHandleNull(null), Throws.ArgumentNullException);

Thank you!

avatar image Tomek-Paszek ♦♦ · Apr 04, 2017 at 03:03 PM 0
Share

You can find more information about the NUnit breaking changes here: https://github.com/nunit/docs/wiki/Upgrading

avatar image
1

Answer by samsmithnz · Jul 06, 2017 at 01:55 PM

The issue here, is that if you install the Unity Test Tools in 5.6, you are effectively installing an error, as this code is added by default:

         [Test]
         [ExpectedException(typeof(ArgumentException), ExpectedMessage = "expected message")]
         public void ExpectedExceptionTest()
         {
             throw new ArgumentException("expected message");
         }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Paul_Bronowski · May 13, 2017 at 04:24 AM

Yes, they moved it... https://github.com/nunit/nunit/issues/113

To here... https://github.com/nunit/nunit-csharp-samples/tree/master/ExpectedExceptionExample

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by rus89 · Sep 22, 2017 at 11:41 AM

@LavaPatrik Replace whole method and all it's attributes with:

 [Test]
         public void ExpectedExceptionTest()
         {
             Assert.Throws<ArgumentException>(delegate()
             {
                 throw new ArgumentException ("expected message");
             });
         }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

102 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unable to see NUnit Assert message output 1 Answer

Editor test runner makes unity hang 1 Answer

How do I test if a 3d model works well in Unity? 0 Answers

[Space Shooter Tutorial] NullReferenceException: Object reference not set to an instance of an object PlayerController.FixedUpdate () 1 Answer

Decrementing a variable in a script in which it was not declared. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges