我对 Jasmine 进行了单元测试。当我运行这个单元测试时,它没有任何错误,但是当我在代码覆盖率中查看它时。它显示一些错误消息:“声明未涵盖”

我想解决这个错误。我能做什么?谢谢
我已经运行 EclEmma 来覆盖我的 JUnit 测试用例,并且在某些方面达到了 100%。但是,对于覆盖 82% 或 95% 的那些,我的代码旁边有一条消息说“错过了 2 个分支中的 1 个”,我似乎无法解决这个问题。
查看我的课程后,我注意到这条消息只出现在我的 if 语句旁边,这就是让我的测试无法 100% 覆盖的原因。
我想我在问是否有人知道如何在 JUnit 中测试 if 语句,以便不会错过任何一个分支。
这是我要测试的代码:
private double height;
public void setHeight(double height){
if(height <=0){
this.height = 0;
}
else{
this.height = height;
}
}//method close
Run Code Online (Sandbox Code Playgroud)
(我正在使用 JUnit 4)
是否可以从VS2017代码覆盖率分析中排除某些方法?
我想要排除简单的getter/setter或简单的工厂(就像胶水代码一样):
public class TimeFactory : ITimeFactory
{
/// <summary>
/// Create a time object -> allows us to simulate time jumps in unit-tests.
/// </summary>
/// <returns></returns>
public IXTimer CreateXTimerObject() => new XTimer();
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我的“测试项目”仅包含 Application.php 和 ApplicationTest.php,但 phpunit 还收集了有关 Composer 自动加载器文件的覆盖率信息,这是错误的。如何从覆盖率报告中排除自动加载器文件?
我仍在学习在我的应用程序中使用 MSTest 和 Moq 进行自动化单元测试。我已经成功地模拟了代码并运行了它。它表明测试通过,但代码覆盖率为 0%。这是我下面的代码。需要更改什么才能使代码覆盖率变为 100%。
我知道这个问题之前曾被问过几次,但似乎没有任何帮助。所以有人可以告诉我我做错了什么。
非常感谢任何帮助。谢谢。
PS:我使用 Sonarcube 来了解代码覆盖率。
using Moq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
namespace MyNameSpace
{
[TestClass]
public class ApplicationTest
{
readonly Helper moqHelper = new Helper();
[TestMethod()]
public void GetDataFromDataBaseMoq()
{
Task<bool> returnValue;
Mock<Application> mockType = new Mock<Application>();
mockType.CallBase = true;
mockType.Setup(x => x.GetDataFromDataBase()).Returns(returnValue = moqHelper.GetDataFromDataBaseMoq());
if (returnValue.Result)
{
Assert.IsTrue(true);
}
else
{
Assert.Fail();
}
}
}
[ExcludeFromCodeCoverage]
class Helper
{
internal async Task<bool> GetDataFromDataBaseMoq()
{
bool returnValue = true;
return returnValue; …Run Code Online (Sandbox Code Playgroud) 我将声纳和Jacoco用于我的Android应用程序代码覆盖率报告。我可以通过设置jacoco任务作业和Sonar作业,然后执行以下命令来成功部署它。
./gradlew clean jacocoTestReport (name of jacoco task)
./gradlew sonarqube (<- mark this)
Run Code Online (Sandbox Code Playgroud)
报告已成功生成,并显示到localhost:9000声纳服务器设置。
我听说了可用于执行相同任务的声纳扫描仪。
我的困惑是我应该在gradlew命令中使用sonar-scanner或sonarqube;它们如何彼此不同。
我有一些代码。但是当我尝试运行覆盖测试并得到响应时:
'go get -u github.com/gregoryv/uncover/...
go test -coverprofile /tmp/c.out
uncover /tmp/c.out'
Run Code Online (Sandbox Code Playgroud)
我尝试安装覆盖包:
go get code.google.com/p/go.tools/cmd/cover
Run Code Online (Sandbox Code Playgroud)
但出现错误
package code.google.com/p/go.tools/cmd/cover: unrecognized import path "code.google.com/p/go.tools/cmd/cover" (parse https://code.google.com/p/go.tools/cmd/cover?go-get=1: no go-import meta tags (meta tag github.com/golang/go did not match import path code.google.com/p/go.tools/cmd/cover))
Run Code Online (Sandbox Code Playgroud)
系统:Ubuntu 18.04
我正在尝试快速进行单元测试。MyFileManager我有一个名为和的两类SomeViewModel
class MyFileManager {
static let shared = MyFileManager()
func isStored(atPath path: String) -> Bool {
return FileManager.default.fileExists(atPath: path)
}
func readData(atPath path: String) -> Data? {
return try? Data(contentsOf: URL(fileURLWithPath: path))
}
}
class SomeViewModel {
func getCachedData() -> Data? {
let path = "xxxxx"
if MyFileManager.shared.isStored(atPath: path) {
return MyFileManager.shared.readData(atPath: path)
} else {
return nil
}
}
}
Run Code Online (Sandbox Code Playgroud)
我写了一个测试代码。我不确定这段代码是否会给我 100% 的代码覆盖率。这是单元测试
class LinePhoneTests: XCTestCase {
override func setUpWithError() throws {
testGetCachedData()
}
func testGetCachedData() …Run Code Online (Sandbox Code Playgroud) 我的项目总体代码覆盖率为72.86%,其中106个测试用例失败,1个跳过测试用例,925个测试用例通过.共有1032个测试用例.覆盖范围内有4个子覆盖范围:
我只知道testbusinesslogic.dll,并让测试通过.我不知道其余的(Business.dll/datalogic.dll/dataobject.dll),因为我无法调试该方法.
这是我第一次做TDD.
下面是datalogic.dll文件中的1个方法,此方法不会出现在我的失败/传递/跳过的测试用例中.这意味着什么?为什么这部分的代码覆盖率会如此之低?如何增加datalogic.dll部分的代码覆盖率?因为我没有失败的测试用例允许我像testbusinesslogic.dll一样通过它
public void GetModelDataForCreate(DataSet availabilityDataSet, int resourceID)
{
Database db = WindowsApplicationTemplate.ApplicationDatabase.DatabaseFactory.CreateDatabase();
string sqlProcedure = "uspAvailabilityGetModelDataForCreate";
DbCommand dbCommand = db.GetStoredProcCommand(sqlProcedure);
UtilityDL.SetCommandTimeout(dbCommand);
db.AddInParameter(dbCommand, "resourceID", DbType.Int32, resourceID);
string[] tables = new string[] { "EventType", "LaborCategory", "Event", "IntelTime", "DurationType", "Resource", "ParameterInfo" };
availabilityDataSet.Clear();
// RETRIEVE DATA FROM DB AND LOAD INTO DATASET
db.LoadDataSet(dbCommand, availabilityDataSet, tables);
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试研究在Jenkins框架上运行的C++代码覆盖工具.你能介绍一下这些工具吗?
给定以下代码片段,100% 的决策覆盖率需要多少次测试?
if width > length then
biggest_dimension = width
if height > width then
biggest_dimension = height
end_if
else
biggest_dimension = length
if height > length then
biggest_dimension = height
end_if
end_if
Run Code Online (Sandbox Code Playgroud)
上述问题的答案是 4 。100% 决策覆盖需要 4 个测试用例。谁能说出以下问题的答案解释?