nus-cs2103-AY1819S1 / forum

A repo to hold the issue tracker for module discussions
1 stars 1 forks source link

Static Analysis and Code Coverage #216

Open aidenywl opened 5 years ago

aidenywl commented 5 years ago

Would it be right to say that static analysis encompasses all forms of code analysis in a non-runtime environment, while dynamic analysis requires a run-time environment?

In the scenario of Code Coverage, these would be static analysis (please correct me if i am wrong):

While these would be considered Dynamic Analysis:

Furthermore, looking at question A.41 of the mock paper, for Intellij, I'm uncertain whether dynamic or static analysis is used. The video here https://www.youtube.com/watch?v=yNYzZvyA2ik was not clear. It seems that if only statement coverage is reported, Intellij's code coverage would be an example of a static analysis?

aaditkamat commented 5 years ago

While IntelliJ does provide a runtime environment, the code coverage analysis is static in nature (code is analysed without executing the instructions). You can check more about this here: IntelliJ Static Code Analysis.

anubh-v commented 5 years ago

I believe some code analysis can be done in a static manner, but I believe test coverage is only done dynamically? (after running the code) ?

CrimsonAng commented 5 years ago

if I not wrong, code coverage should be dynamically, only after running the code then it know how much path, branch etc covered.

[Running with Coverage IntelliJ IDEA provides a dedicated action that allows you to perform run with code coverage measurement]

from https://www.jetbrains.com/help/idea/running-test-with-coverage.html

damithc commented 5 years ago

Coverage analysis normally requires the tests to be run first, which means it is not static but dynamic analysis. Last time I checked, Intellij requires running of tests prior to generating coverage stats too. But intellij can provide a whole lot of other information based on static analysis e.g., dead code, unused variables, redundant parentheses, etc.