How to Run Unit Tests in Eclipse and Visual Studio
The main unit test frameworks include JUnit, MSTest, TestNG, and NUnit. All provide an easy way to organize and run test methods, but users are often confused by the fact that unit test classes do not contain a "main" function, which means they cannot initially be run with the Play/Start button available in Visual Studio or Eclipse.
Here are some quick instructions on how to execute these unit tests in both Eclipse and Visual Studio.
To run JUnit or TestNG tests in Eclipse right click on the project, unit test class, or unit test function name and select Run As >> JUnit or TestNG. (JUnit should be available in Eclipse by default but an additional plugin has to be installed for TestNG.)
In Visual Studio, MSTest is supported by default and is used in the templates included with the Perfecto Lab Projects.
- 1. First, build the project (BUILD >> Build Solution)
- 2. Ensure the Test Explorer Window is open (TEST >> Windows >> Test Explorer)
- 3. If the project is built successfully, all test names will appear in the Test Explorer
- 4. Select Run All or select individual tests to run in the Test Explorer. If you right click on a test name and select run tests you can also run that individual test.
Perfecto's Continuous Quality Lab helps perfect the digital experiences that define your brand. Learn more