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
0
Question by BrewNCode · Aug 30, 2017 at 07:37 PM · c#beginner

How can you test your code with no assets yet.

Hello, guys, I'm going to start a project for college, and I want to test my codes before using them. How can I do this if I still haven't got the assets from the artist?

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

1 Reply

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

Answer by MaxGuernseyIII · Aug 30, 2017 at 08:09 PM

Use the discipline of test-driven development.

Visual Studio 2017 and Unity integrate very well and the Community edition of Visual Studio is free.

  1. Install Visual Studio 2017 (or better).

  2. Make sure Visual Studio is your editor.

  3. Open your script from Unity, this will create a Visual Studio solution that is "aware" of your Unity stuff.

I like to put all my "scripts" into assemblies that compile to a Unity target platform and change their output to go to Assets\bin for my Unity project. Then I can do things like make other assemblies (such as test assemblies) depend on them.

Once you have your code organized, you can do just that:

  1. Add a new project to your test solution.

  2. Add a reference from your test project to the project containing your scripts.

Then you will be in a position to use test-driven development.

  1. Write a test that expresses how a class should work.

  2. Stub out enough of the class to see the test fail.

  3. Make the test pass.

  4. Refactor for quality.

  5. Repeat.

Don't make the mistake of having the stuff you TDD be coupled to MonoBehaviour - make separate classes and then adapt them into Unity with thing, crispy implementations of MonoBehaviour.

Unity also has a test runner but, for coding, there is no development environment that matches Visual Studio.

Since you are ostensibly young, I'll also add this advice: don't believe anyone who says "TDD doesn't apply to X". It applies to everything, you just have to eliminate the barriers we create for ourselves first, sometimes.

If by "test" you mean "manually interact with", like exploratory testing or something, then you can just create dummy assets. Your code shouldn't be coupled to the assets you use anyway.

That said, if you are a coder, you're way better off having precise definitions of the exact behaviors you want in your code base and a way to virtually instantly tell which ones are working the way you intend.

EDIT

Attaching a reference solution that can be used to validate a Visual Studio install.

Reference Solution - Download this, unzip it, and open up the .SLN file. If the projects build and you can run the tests, your Visual Studio install is ready. You can also poke through the settings to see how I set the target to a Unity platform and pointed the output to a build directory in a "unity project" (which I model with an empty folder because those are too large for this answers exchange).


writecodeinvisualstudio.zip (16.1 kB)
Comment
Add comment · Show 7 · 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 MaxGuernseyIII · Aug 30, 2017 at 08:10 PM 0
Share

I think this goes without saying but you don't need to repeat the setup steps, just the TDD part (write a test, see it fail, make it pass, refactor).

avatar image BrewNCode · Aug 30, 2017 at 09:03 PM 0
Share

When I open my file with visual studio 2017, it says that is an incompatible file.alt text

2017-08-30.png (130.8 kB)
avatar image MaxGuernseyIII · Aug 30, 2017 at 11:20 PM 0
Share

There are a lot of reasons that could be:

  1. You might have opened the wrong kind of thing from Visual Studio.

  2. You may have not installed the Unity workload in Visual Studio.

  3. The Visual Studio-unity integration sometimes wants you to open Visual Studio directly from Unity.

  4. I'm sure there are others.

In any event, assu$$anonymous$$g you have the Unity tools installed in VS, you can do things by hand the first time:

  1. Create a new project using the class library (.Net framework) template.

  2. Change the target framework to one of the Unity platforms (if you don't have them, you haven't installed the Unity workload).

  3. Change the output path of the production assembly to point to your Assets/bin folder.

  4. Create a test project using an appropriate template.

  5. Add a reference from your test project to your production project.

Start doing TDD.

avatar image BrewNCode MaxGuernseyIII · Aug 31, 2017 at 12:36 AM 0
Share

O$$anonymous$$, I don't have the Unity class library installed. Do I have to uninstall VS 2017 and re-install it? Or I can do it manually?

avatar image MaxGuernseyIII · Aug 31, 2017 at 01:53 AM 0
Share

You can add or remove the components with the Visual Studio Installer. That should be available from somewhere in your start menu. I'm out to eat with my wife and children but I'll send you a very small reference solution when I get home, if you like. You shouldn't use it to do your work but you can use it to validate your Visual Studio install and to help guide building your own solution.

avatar image BrewNCode MaxGuernseyIII · Aug 31, 2017 at 12:22 PM 0
Share

Thank you very much for your help, Now my VS is updating. I guess now I can find the Unity extension.

avatar image MaxGuernseyIII · Aug 31, 2017 at 07:23 PM 0
Share

Added the reference solution to the main answer.

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

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

Best way to learn how to utilize the Unity API? 2 Answers

Accessing Variables inside classes inside other classes? 1 Answer

Raycast shotgun help! 2 Answers

What is wrong with my code? C# beginner 1 Answer

why the Timer isn't working 0 Answers


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