4

I've done a little bit of Unit Testing using JUnit with a Java program, and I am new to the .NET unit testing space. I'm sure it can't be so different, though.

At work, we have a legacy VB .NET codebase, with zero unit testing going on. I want to start adding some unit testing to this thing, and I see the option in Visual Studio to use C# for unit testing.

My question is, am I even able to use C# for testing the VB code? I would definitely want to use this as an opportunity to work with C# instead of more VB. I can't find this question anywhere else online, interestingly enough, and would love some insight. It seems like I'm asking a dumb question, but I hope to get an answer that would help me understand this, especially as to why it's a dumb question, if it is.

4
  • 1
    Can't see a reason this wouldn't work but... I'm not sure it's a good idea. Making people context switch between languages when writing tests is extra cognitive load you don't need. Commented Apr 3, 2019 at 15:27
  • 3
    Yes, VB.NET and C# work together pretty seamlessly. You can even do C# and F#, but in that case you run into some problems with the fact that they typically use completely different collection classes. Commented Apr 3, 2019 at 15:29
  • Don't get why users are so harsh with this, I wanted to ask before i spent time with it, I don't think that's so crazy. Sheesh.. Thank's to the ones who provided some useful info, appreciate it Commented Apr 3, 2019 at 15:33
  • 1
    There's nothing wrong with wanting to be more conversant in C#, but it doesn't seem like a good idea to do it by arbitrarily using a different language for writing production code for testing a VB project. I think you'd be better off using a VB test project and doing something else to exercise your C# skills. Commented Apr 4, 2019 at 14:20

1 Answer 1

8

Welcome to .Net

So short answer is yes. You can have a new unit/integration test project which can be in C# which effectively can test code written in any other .Net compliant language.

So how this works?

.Net is multi language framework. VB and C# are just popular ones. Once code written in any .Net compliant language it get compiled in IL code which is kind of similar to byte code in java and packed in DLL file.

So once dll is built, it can be referenced by any project using any .Net complaint language.

So how will you do it?

  1. Create another project for unit/integration testing using any unit testing framework templates such nunit, mstest, xunit (do some analysis and choose yours)
  2. Reference you VB project in C# test project so that you can access classes from VB code.
  3. Use some tutorial how to write test cases based on testing framework you choose.
Sign up to request clarification or add additional context in comments.

1 Comment

Really appreciate your complete answer! I think I will stick with VB just for consistency.

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.