Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use C# for doing unit testing on VB code?

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.

like image 338
shmob Avatar asked Oct 19 '25 08:10

shmob


1 Answers

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.
like image 90
Chaturvedi Dewashish Avatar answered Oct 20 '25 23:10

Chaturvedi Dewashish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!