#c# #.net #unit-testing #build #azure-devops
#c# #.net #модульное тестирование #сборка #azure-devops
Вопрос:
я новичок в процессе сборки .net core, поэтому мой вопрос может быть простым, но я не мог понять его до сих пор. Так что любой намек будет оценен!
Я создал решение Visual Studio, следуя этой структуре
MoCap1 (the solution)
- src
- C3D (my main project)
- project.json (etc.)
- test
- C3D.Tests (the corresponding test project)
- project.json (etc.)
- C3DParserTests.cs (the file containing the test mentioned below)
Эта структура используется на диске и в обозревателе решений в Visual Studio 2015
В C3DParserTests.cs я определил следующий тест:
[Fact]
public void Parse()
{
/*
* positive tests
*/
C3DParser parser = new C3DParser();
C3DModel model = parser.Parse(File.ReadAllBytes(@"DataHDM_bd_01-01_01_120.c3d"));
Assert.NotNull(model);
// check header info
Assert.Equal(2, model.ParameterSectionStart);
}
Как вы можете видеть, ссылка на файл .c3d. При использовании Visual Studio для тестирования файл может быть найден, и тест пройден успешно. При использовании teamservices и моего процесса сборки я получаю следующую ошибку:
xUnit.net .NET CLI test runner (64-bit .NET Core win81-x64)
Discovering: C3D.Tests
Discovered: C3D.Tests
Starting: C3D.Tests
C3D.Tests.C3DParserTests.Parse [FAIL]
System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:a1sDataHDM_bd_01-01_01_120.c3d'.
Stack Trace:
at System.IO.Win32FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
at System.IO.Win32FileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.File.InternalReadAllBytes(String path)
at System.IO.File.ReadAllBytes(String path)
C:a1sMoCap1testC3D.TestsC3DParserTests.cs(22,0): at C3D.Tests.C3DParserTests.Parse()
C3D.Tests.C3DParserTests.ParseNegative [FAIL]
System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:a1sDataHDM_bd_01-01_01_120.c3d'.
Stack Trace:
at System.IO.Win32FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
at System.IO.Win32FileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.File.InternalReadAllBytes(String path)
at System.IO.File.ReadAllBytes(String path)
C:a1sMoCap1testC3D.TestsC3DParserTests.cs(40,0): at C3D.Tests.C3DParserTests.ParseNegative()
Finished: C3D.Tests
=== TEST EXECUTION SUMMARY ===
C3D.Tests Total: 4, Errors: 0, Failed: 2, Skipped: 0, Time: 0.349s
SUMMARY: Total: 1 targets, Passed: 0, Failed: 1.
Process completed with exit code 1.
Это имеет смысл, поскольку путь
C:a1sDataHDM_bd_01-01_01_120.c3d
не существует. Это вывод для этапа сборки, где вы можете увидеть правильный путь
Done Building Project "C:a1sMoCap1srcC3DC3D.xproj" (default targets).
The target "_ConvertPdbFiles" listed in a BeforeTargets attribute at "C:Program Files (x86)MSBuild14.0Microsoft.Common.targetsImportAfterXamarin.Common.targets (34,37)" does not exist in the project, and will be ignored.
The target "_CollectPdbFiles" listed in an AfterTargets attribute at "C:Program Files (x86)MSBuild14.0Microsoft.Common.targetsImportAfterXamarin.Common.targets (34,70)" does not exist in the project, and will be ignored.
The target "_CollectMdbFiles" listed in a BeforeTargets attribute at "C:Program Files (x86)MSBuild14.0Microsoft.Common.targetsImportAfterXamarin.Common.targets (41,38)" does not exist in the project, and will be ignored.
The target "_CopyMdbFiles" listed in an AfterTargets attribute at "C:Program Files (x86)MSBuild14.0Microsoft.Common.targetsImportAfterXamarin.Common.targets (41,71)" does not exist in the project, and will be ignored.
Project "C:a1sMoCap1MoCap1.sln" (1) is building "C:a1sMoCap1testC3D.TestsC3D.Tests.xproj" (3) on node 1 (default targets).
PrepareForBuild:
Creating directory ".bin".
Creating directory ".objRelease".
CoreCompile:
C:Program Filesdotnetdotnet.exe build "C:a1sMoCap1testC3D.Tests" --configuration Release --no-dependencies
Project C3D.Tests (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling C3D.Tests for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:01.8894809
Done Building Project "C:a1sMoCap1testC3D.TestsC3D.Tests.xproj" (default targets).
Done Building Project "C:a1sMoCap1MoCap1.sln" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:43.29
Этап сборки dotNet для тестирования выдает следующий результат:
Starting: Run dotnet
******************************************************************************
dotnet test C:a1sMoCap1testC3D.Tests -xml testresultsC3D.xml
Project C3D (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling C3D for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:01.8492346
Project C3D.Tests (.NETCoreApp,Version=v1.0) will be compiled because dependencies changed
Compiling C3D.Tests for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:01.7167452
Не могли бы вы дать мне какой-либо совет, как решить эту проблему?
С наилучшими пожеланиями,
Nils
Комментарии:
1. Как создать проект xunittest для основного проекта? Вы можете предоставить подробные инструкции или поделиться простым проектом на OneDrive.
2. Я ссылался на эту статью ( xunit.github.io/docs/getting-started-dotnet-core.html ) для создания проекта xunit. Он отлично строится. (связанный код [Факт] public void ReadFileTest() { байт [] b = Файл. ReadAllBytes(@»Data2tt.txt «); результат строки = System.Text.Encoding.UTF8.getString(b); Утверждение. Равно («привет», результат); }). Каковы детали ваших шагов сборки, как вы указываете рабочую папку шага командной строки?
3. Для запуска теста я использую шаг командной строки (тест dotnet).
4. Какова структура вашего проекта?
5. Является ли файл «HDM_bd_01-01_01_120.c3d» сгенерированным сборкой?