SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.25k stars 754 forks source link

SpecRun + MSSQL + Database logging #2021

Closed borsooq closed 2 years ago

borsooq commented 4 years ago

SpecFlow Version:

Used Test Runner

Version number:

Project Format of the SpecFlow project

.feature.cs files are generated using

Visual Studio Version

Enable SpecFlowSingleFileGenerator Custom Tool option in Visual Studio extension settings

Are the latest Visual Studio updates installed?

.NET Framework:

Test Execution Method:

<SpecFlow> Section in app.config or content of specflow.json

Repro Project

Issue Description

SpecRun Server does not populate results to the database

Steps to Reproduce

  1. Set the database for SpecRun server use
  2. Initialize it
  3. Configure srprofile to use SpecRun server
  4. Run the test
  5. Check Database content
  6. Verify logs

I have a problem with database storing results configuration.

My srprofile is:

<?xml version="1.0" encoding="utf-8"?> <TestProfile xmlns="http://www.specflow.org/schemas/plus/TestProfile/1.5"> <Settings projectName="myProject" name="MyName" projectId="{7B359152-D36D-4D5A-BFDB-ED78B094D619}"/> <Report><Template name="ReportTemplate.cshtml" outputName="MyOutputName"/></Report> <Execution stopAfterFailures="0" retryFor="Failing" retryCount="1" testThreadCount="1" testSchedulingMode="Adaptive" /> <!-- For collecting by a SpecRun server update and enable the following element. For using the collected statistics, set testSchedulingMode="Adaptive" attribute on the <Execution> element.--> <Server serverUrl="http://127.0.0.1:6365" publishResults="true" />

<TestAssemblyPaths> <TestAssemblyPath>UITestSF.dll</TestAssemblyPath> </TestAssemblyPaths> <DeploymentTransformation> <Steps> <ConfigFileTransformation configFile="App.config"> <Transformation> <![CDATA[<?xml version="1.0" encoding="utf-8"?> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <appSettings> <add key="environment" value="myEnvironment" xdt:Locator="Match(key)" xdt:Transform="Insert"/> </appSettings> </configuration> ]]> </Transformation> </ConfigFileTransformation> </Steps> </DeploymentTransformation> </TestProfile>

Following the instruction:

https://specflow.org/plus/documentation/Setting-up-the-SpecFlowPlus-Runner-Server/

I set up a MSSQL Express DB and initialized it with SpecRun.Server.exe initdatabase command. I see that it has been initialized as I can see newly created tables in it.

Setup of my SpecRun.Server.exe.config

`<?xml version="1.0" encoding="utf-8"?>

` I set up everything what was possible to Verbose or Info. When I am executing the test, I see that the specrun server reacts as logs are stored and some queries are transfered on the wires, but the DB stays untouched. No data stored there. I also can see in VS: starting test run Discovering target: Default Discovering tests from assembly: C:\Tests\UITestSF\bin\Debug\UITestSF.dll Discovered tests from assembly: C:\Tests\UITestSF\bin\Debug\UITestSF.dll Received 0 execution hints from SpecRun server in 2,92 seconds. Is there anything that I could do to verify what's going on?
borsooq commented 4 years ago

I figured out that SpecRun is collecting data (at least is trying), but doesn't even try to populate them to the database. See the profiler logs below: image image

Anyone can help me? Anyone has the setup working?

SabotageAndi commented 4 years ago

Could you check the log file if there is more output what is happening?

borsooq commented 4 years ago

Could you check the log file if there is more output what is happening?

2020-07-02T14:06:18.0455118+02:00;Thread#1;Info;Reading test run result from Json file "C:\Users\mkbu\AppData\Local\Temp\tmpDE4D.tmp". 2020-07-02T14:06:18.0484718+02:00;Thread#1;Info;Successfully read test run result from Json file "C:\Users\mkbu\AppData\Local\Temp\tmpDE4D.tmp" 2020-07-02T14:06:18.0484718+02:00;Thread#1;Info;Deserializing test run result 2020-07-02T14:06:18.1910911+02:00;Thread#1;Info;Successfully deserialized test run result 2020-07-02T14:06:18.1910911+02:00;Thread#1;Info;Loading test run result 2020-07-02T14:06:18.2150263+02:00;Thread#1;Info;Successfully loaded test run result 2020-07-02T14:06:18.2269949+02:00;Thread#1;Info;creating 1 report(s) 2020-07-02T14:06:18.2269949+02:00;Thread#1;Info;generate Report ReportTemplate.cshtml 2020-07-02T14:06:19.0687421+02:00;Thread#1;Info;Finished generating reports. ========== End of log file ==========

Brand new solution created specifcally for testing that feature.

I see that the build itself is old as hell. Most of the files are from 2011, also required Newtonsoft JSON is of 4.0.2 version. There is no server folder in tool folder for builds for .net Core 2.1 and 3.1. Is it obsolete and not supported anymore?

image

image

`C:\Users\mkbu\source\repos\SpecflowSpecrunServer\packages\SpecRun.Runner.3.3.17\tools\net461\server>SpecRun.Server.exe initdatabase

Unhandled Exception: System.Data.DataException: An exception occurred while initializing the database. See the InnerException for details. ---> System.Data.EntityCommandCompilationException: An error occurred while preparing the command definition. See the inner exception for details. ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=4.0.2.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at System.Data.Metadata.Edm.MetadataAssemblyHelper.SafeLoadReferencedAssembly(AssemblyName assemblyName) at System.Data.Metadata.Edm.MetadataAssemblyHelper.d__8.MoveNext() at System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadViewsFromAllReferencedAssemblies(Assembly assembly) at System.Data.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedCollectViewsFromReferencedAssemblies(MetadataWorkspace workspace, Dictionary2 extentMappingViews) at System.Data.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGetGeneratedViews(EntityContainer container) at System.Data.Common.Utils.Memoizer2.Result.GetValue() at System.Data.Common.Utils.Memoizer2.Evaluate(TArg arg) at System.Data.Mapping.StorageMappingItemCollection.ViewDictionary.GetGeneratedView(EntitySetBase extent, MetadataWorkspace workspace, StorageMappingItemCollection storageMappingItemCollection) at System.Data.Metadata.Edm.MetadataWorkspace.GetGeneratedView(EntitySetBase extent) at System.Data.Query.PlanCompiler.PreProcessor.ExpandView(Node node, ScanTableOp scanTableOp, IsOfOp& typeFilter) at System.Data.Query.PlanCompiler.PreProcessor.ProcessScanTable(Node scanTableNode, ScanTableOp scanTableOp, IsOfOp& typeFilter) at System.Data.Query.PlanCompiler.PreProcessor.Visit(ScanTableOp op, Node n) at System.Data.Query.PlanCompiler.SubqueryTrackingVisitor.VisitChildren(Node n) at System.Data.Query.PlanCompiler.SubqueryTrackingVisitor.VisitRelOpDefault(RelOp op, Node n) at System.Data.Query.PlanCompiler.PreProcessor.Visit(ProjectOp op, Node n) at System.Data.Query.PlanCompiler.SubqueryTrackingVisitor.VisitChildren(Node n) at System.Data.Query.PlanCompiler.SubqueryTrackingVisitor.VisitRelOpDefault(RelOp op, Node n) at System.Data.Query.PlanCompiler.SubqueryTrackingVisitor.VisitChildren(Node n) at System.Data.Query.InternalTrees.BasicOpVisitorOfNode.VisitDefault(Node n) at System.Data.Query.PlanCompiler.PreProcessor.Process(Dictionary2& tvfResultKeys) at System.Data.Query.PlanCompiler.PreProcessor.Process(PlanCompiler planCompilerState, StructuredTypeInfo& typeInfo, Dictionary2& tvfResultKeys) at System.Data.Query.PlanCompiler.PlanCompiler.Compile(List1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set1& entitySets) at System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree) --- End of inner exception stack trace --- at System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree) at System.Data.EntityClient.EntityProviderServices.CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree) at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, ReadOnlyCollection1 compiledQueryParameters, AliasGenerator aliasGenerator) at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable1 forMergeOption) at System.Data.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) at System.Data.Objects.ObjectQuery1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source) at System.Data.Entity.Internal.InternalContext.QueryForModelHash() at System.Data.Entity.Internal.InternalContext.CompatibleWithModel(Boolean throwIfNoMetadata) at System.Data.Entity.CreateDatabaseIfNotExists1.InitializeDatabase(TContext context) at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) --- End of inner exception stack trace --- at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() at System.Data.Entity.Internal.RetryAction1.PerformAction(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action1 action) at System.Data.Entity.Internal.InternalContext.ExecuteSqlCommand(String sql, Object[] parameters) at System.Data.Entity.Database.ExecuteSqlCommand(String sql, Object[] parameters) at TechTalk.SpecRun.Server.Model.ReadModel.ReadModelDbContext.RecreateDatabase() at TechTalk.SpecRun.Server.DatabaseInitializer.InitDatabase() at lambda_method(Closure , Object , Object[] ) at NConsoler.Consolery.Run(Type targetType, String[] args, IMessenger messenger, Notation notationType) at TechTalk.SpecRun.Server.Program.Main(String[] args)`

SabotageAndi commented 4 years ago

When I remember correctly, the OData library we are using doesn't like newer Newtonsoft.Json versions. The Server is not available in the netcore3.1 and netcore2.1 folders are, we didn't port it to .NET Core. It's only available for Full Framework.

I looked into the NuGet package. We are packaging the wrong file into the server folder. That's a 11.0 Newtonsoft.Json. Until we published a new version with the fixed assembly, you should be able to download the old NuGet package from NuGet.org and change the file on your own.

borsooq commented 4 years ago

I did it, so I have some logs, because otherwise the server crashes immediately. Could you please test it, when you have access to source files if it still works?

SabotageAndi commented 2 years ago

As we stopped maintaining the SpecFlow+ Runner (https://specflow.org/using-specflow/the-retirement-of-specflow-runner/) I am closing this issue.

github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.