简体   繁体   中英

Does 100% code coverage mean that the code is correct?

If you have 100% test coverage and all tests pass does that mean that the code is guaranteed to be correct and writing more tests is pointless?

It's only correct as far as the logic of your testing is correct.

I'll give the most stupid example possible...

If I for example have a class (Java):

public class Example {

    public int timesTwo(int x){
        return x*2;
    }

}

with the following test (which you can see it being illogical and useless)

public class ExampleTest {

    @Test
    public void timesTwo() {
        new Example().timesTwo(5);
        assertTrue(true);
    }
    
}

Most coverage tools will say that this class has been tested 100%, So no; coverage is a good indicator of what needs to be tested. but the test logic itself isn't assured.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM