简体   繁体   English

覆盖范围不能覆盖public static void main方法

[英]Coverage can't cover the public static void main method

Using Junit coverage, it can't cover public static void main method. 使用Junit覆盖,它不能覆盖public static void main方法。 How can I cover it? 我该怎么说呢?

After making sure it's testable just call it as any other public static method: 在确定它是可测试的之后,只需将其称为任何其他公共静态方法:

YourClass.main(new String[] {"parameter 1", "parameter 2"});

And assert the following state afterwards. 然后断言以下状态。

Because it does not return anything, you cannot check the output. 因为它不返回任何内容,所以无法检查输出。 But what does it do? 但是它做了什么? If it calls another method the write a test for that method. 如果它调用另一种方法,则为该方法编写测试。 If it doesn't call other methods, then write a test for that. 如果它没有调用其他方法,那么为此编写一个测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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