Trying to learn about Unit Tests

I'm following the example on https://docs.microsoft.com/en-gb/visualstudio/test/walkthrough-creating-and-running-unit-tests-for-managed-code
to learn about unit testing.
When I add the reference to Bank.sln I'm getting a message:

A reference to D:\Documents\UnitTesting\Bank\Bank.sln could not be added.  Please make sure that the file is accessible, and that it is a valid assembly or COM component.
Could it be because Visual Studio 2017 is installed on my C drive and this project is on my D drive?  I'm using C#.net
AlHal2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technical NinjaCommented:
Can you explain where it is asking to add a reference to Bank.sln, generally you add reference to assemblies, not a solution file.
0
AlHal2Author Commented:
Here are the instruction I've followed.  I've also attached a screenshot.

Create a project to test
Open Visual Studio.

On the File menu, select New > Project.

The New Project dialog box appears.

Under Installed Templates, click Visual C#.

In the list of application types, click Class Library.

In the Name box, type Bank and then click OK.

Note

If the name "Bank" is already used, choose another name for the project.

The new Bank project is created and displayed in Solution Explorer with the Class1.cs file open in the code editor.

Note

If the Class1.cs file is not open in the Code Editor, double-click the file Class1.cs in Solution Explorer to open it.

Copy the source code from the Sample Project for Creating Unit Tests, and replace the original contents of Class1.cs with the copied code.

Save the file as BankAccount.cs.

On the Build menu, click Build Solution.

You now have a project named Bank. It contains source code to test and tools to test it with. The namespace for Bank, BankAccountNS, contains the public class BankAccount, whose methods you'll test in the following procedures.

In this article, the tests focus on the Debit method. The Debit method is called when money is withdrawn from an account. Here is the method definition:

C#

Copy
// Method to be tested.
public void Debit(double amount)
{
    if(amount > m_balance)
    {
        throw new ArgumentOutOfRangeException("amount");
    }
    if (amount < 0)
    {
        throw new ArgumentOutOfRangeException("amount");
    }
    m_balance += amount;
}
Create a unit test project
On the File menu, select Add > New Project.

In the New Project dialog box, expand Installed, expand Visual C#, and then choose Test.

From the list of templates, select Unit Test Project.

In the Name box, enter BankTests, and then select OK.

The BankTests project is added to the Bank solution.

In the BankTests project, add a reference to the Bank project.

In Solution Explorer, select References in the BankTests project and then choose Add Reference from the context menu.

In the Reference Manager dialog box, expand Solution and then check the Bank item.
Screenshot.docx
0
ste5anSenior DeveloperCommented:
Just a comment:

You set references in solutions to projects.. maybe that is the problem..

but really, an image embedded in a Word instead of attaching it directly or embedding it into your post using the image button in the toolbar?

Capture.PNG
2
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Chinmay PatelChief Technical NinjaCommented:
As mentioned earlier, you are supposed to add reference to the assembly of Banks project.
References Section
0
ste5anSenior DeveloperCommented:
E.g. setting the reference directly to the project:

Capture.PNG
0
käµfm³d 👽Commented:
Could it be because Visual Studio 2017 is installed on my C drive and this project is on my D drive?
Nope, that has nothing to do with anything. You can even add a reference from a network share if your account can see the share. The problem is as other mentioned.
0
AlHal2Author Commented:
This is what I did.

In Solution Explorer, select References in the BankTests project and then choose Add Reference from the context menu.

I selected Banks.sln by checking the box then clicking OK.  Then I got the error message above.

Is Banks.sln the right file to look for?
0
ste5anSenior DeveloperCommented:
No, it's not. As I already wrote, you can only reference projects.

Look at the image I've posted:

You need to select Projects>Solutions on the left side. Then you should see all projects of your current solution minus the actual one, where you want to add the reference.

When you still cannot find it, maybe it's time to consider posting more information, like an image of your current solution?!
0
AlHal2Author Commented:
Sorry.  I thought an sln file represented a project.
I then hit on the idea of building the solution and linking this to the DLL file.
That seemed to work.  Am I correct now?
0
ste5anSenior DeveloperCommented:
Maybe. Referencing the assembly directly, means that you can test against an old build. Referencing against the project ensures that you always uses at least the latest build.

sln is solution. Just strip the vowels and the t.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlHal2Author Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.