Difference b/w running test cases in angular frameworks vs the compiler default?

29 Views Asked by At

Diff b/w running angular testing in jasmine / karma etc vs doing it in the ng serve when the project gets saved & compiled automatically. Why is there a need for the testing Framework in angular like Jasmine / karma / protractor etc. ?

1

There are 1 best solutions below

1
Mukesh On

Running Angular tests in Jasmine/Karma or using the ng serve command serve different purposes and have distinct advantages.

ng serve for development and real-time feedback: When using ng serve, the Angular CLI compiles your application and launches a development server that automatically refreshes the browser whenever you save changes to your code. This is ideal for development as it provides a fast feedback loop and allows you to quickly iterate on your code. However, it does not perform extensive testing or provide detailed test reports.

Testing frameworks (Jasmine/Karma/Protractor) for comprehensive testing: Testing frameworks like Jasmine, Karma, and Protractor are designed specifically for testing Angular applications. They offer a range of features and benefits:

  • Test Structure: Testing frameworks provide a structured way to write and organize tests. They allow you to define test suites, test cases, and assertions, making it easier to manage and maintain your tests.
  • Test Coverage: Testing frameworks provide tools to measure the code coverage of your tests. They help ensure that your tests cover a significant portion of your codebase, reducing the risk of undetected bugs.
  • Assertions and Matchers: Testing frameworks provide built-in assertion functions and matchers, which allow you to express expectations about the behavior of your code. These assertions help validate that your code is working correctly.
  • Mocking and Spies: Testing frameworks often provide mechanisms for mocking dependencies and spying on function calls. This allows you to isolate units of code for testing and verify that functions are called with the expected arguments.
  • Test Reports: Testing frameworks generate detailed test reports, showing which tests passed and which failed. These reports provide valuable feedback, especially in larger projects with numerous tests.
  • Continuous Integration (CI) and Automation: Testing frameworks integrate well with CI systems, allowing you to automatically run tests on code commits or schedule them for regular execution. They enable you to catch bugs early and maintain the quality of your application throughout its development lifecycle.

Overall, while ng serve is great for rapid development and quick feedback, testing frameworks like Jasmine, Karma, and Protractor provide a more comprehensive and structured approach to testing your Angular application. They offer features and tools specifically tailored to the needs of testing, including advanced assertions, code coverage analysis, and test reports, among others.