Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
2

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
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

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.

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

Unity Tests Deactivates Test Object 0 Answers

Deserialization during Unit Testing 0 Answers

Type or namespace of certain packages could not be found after unity testing framework was set up 0 Answers

Make a relation between color and distance between objects' x coordinates 0 Answers

Error in child particle systems (2017 2.0b11) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges