Run unit tests in Eclipse and Visual Studio | NUnit
A common hurdle when first learning to use IDEs like Eclipse and Microsoft Visual Studio is to attempt to execute unit tests like a normal Java or C# program. Unit Test frameworks include JUnit, MSTest, TestNG, and NUnit. They provide an easy way to organize and run test methods. What can be confusing is that unit test classes do not contain a main
function, which means that they cannot initially be run with the Play/Start button available in VS or Eclipse.
JUnit should be available in Eclipse by default, but an additional plugin has to be installed for TestNG.
Visual Studio supports MSTest by default and is used in the templates included with the Perfecto Lab projects.
- Right-click the project, unit test class, or unit test function name and select Run As > JUnit or TestNG.
-
Build the project (BUILD > Build Solution).
-
Make sure the Test Explorer window is open (TEST > Windows > Test Explorer).
If the project is built successfully, all test names appear in the Test Explorer.
-
In the Test Explorer, do one of the following:
-
Click Run All to run all tests.
-
Click Run > <test name> or right-click a test and select Run test to run an individual test.
-