Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show proper warning message no tests to run because testcasefilter #1656

Merged
merged 11 commits into from
Jun 25, 2018

Conversation

smadala
Copy link
Contributor

@smadala smadala commented Jun 20, 2018

Description

For #1643

  • Show better warning message on no tests discover/run when testcasefilter provided.
  • As the testcasefilter can be really lengthy in LUT scenarion.
    1. Showing entire testcasefilter can cause following issues.
      a. Small scrollpane for output -> test
      b. Lengthy message can impact the performance of VS
    2. Showing no given testcasefilter can lead to no proper logging/diagnostic information for user. Having proper logging/diagnostic info can help the user to understand the issue and help themselves.
      Example issue

First I have chosen 60 character as max testcasefilter length. While testing realized that max length 256 characters looks good.

For #1569

Related issue

#1643
#1569

@smadala smadala changed the title [WIP] Show proper warning message no tests to run because testcasefilter Show proper warning message no tests to run because testcasefilter Jun 21, 2018
@@ -6,8 +6,8 @@
<!-- Name of the elements must be in sync with test\Microsoft.TestPlatform.TestUtilities\IntegrationTestBase.cs -->
<NETTestSdkPreviousVersion>15.5.0</NETTestSdkPreviousVersion>

<MSTestFrameworkVersion>1.3.2</MSTestFrameworkVersion>
<MSTestAdapterVersion>1.3.2</MSTestAdapterVersion>
<MSTestFrameworkVersion>1.3.1</MSTestFrameworkVersion>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change required to show proper diagnostic info on test failures of vstest repo. Related to microsoft/testfx#451 . We should fix the trx parsing logic in vstest repo.

datadriven_h

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets create a tracking bug for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created one #1658

this.requestData.MetricsCollection.Add(TelemetryDataConstants.TimeTakenInSecByAllAdapters, totalTimeTakenByAdapters);
private static void LogWarningOnNoTestsDiscovered(IEnumerable<string> sources, string testCaseFilter, IMessageLogger logger)
{
var sourcesString = string.Join(" ", sources);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual change is here for discovery scenario.

@@ -170,5 +186,22 @@ protected override void InvokeExecutor(LazyExtension<ITestExecutor, ITestExecuto

return result;
}

private static string TestCaseFilterToShow(string testCaseFilter)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dead code.

@@ -11,7 +11,10 @@
<!--<EnableCodeAnalysis>true</EnableCodeAnalysis>-->
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Resources.resx" />
<EmbeddedResource Include="Resources\Resources.resx">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To Make Resources.Designer.cs updates based on Resources.resx.

Example: SettingsMigrator.exe E:\MyTest\MyTestSettings.testsettings
Example: SettingsMigrator.exe E:\MyTest\MyOldRunSettings.runsettings</source>
<target state="translated">Platné použití: SettingsMigrator.exe &lt;kompletní cesta k souboru testsettings nebo runsettings, který se má migrovat&gt;
<source>Valid usage:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These resources update missed in #1620
/cc @singhsarab @kaadhina

@@ -147,6 +147,12 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory)
events.TestRunMessage += this.TestMessageHandler;
events.TestResult += this.TestResultHandler;
events.TestRunComplete += this.TestRunCompleteHandler;

// Register for the discovery events.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for #1569. ported from #1111

/cc @abhishkk

@@ -6,8 +6,8 @@
<!-- Name of the elements must be in sync with test\Microsoft.TestPlatform.TestUtilities\IntegrationTestBase.cs -->
<NETTestSdkPreviousVersion>15.5.0</NETTestSdkPreviousVersion>

<MSTestFrameworkVersion>1.3.2</MSTestFrameworkVersion>
<MSTestAdapterVersion>1.3.2</MSTestAdapterVersion>
<MSTestFrameworkVersion>1.3.1</MSTestFrameworkVersion>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets create a tracking bug for this.

@@ -135,93 +135,174 @@ private void LoadTestsFromAnExtension(string extensionAssembly, IEnumerable<stri

foreach (var discoverer in discovererToSourcesMap.Keys)
{
Type discovererType = null;
this.DiscoverTestsFromSingleDiscoverer(discoverer, discovererToSourcesMap, context, discoverySink, logger, ref discoverersFromDeprecatedLocations, ref totalAdaptersUsed, ref totalTimeTakenByAdapters);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using ref and out in C#. Check this CA violation for more details.
Additional read: https://www.simplethread.com/ten-c-keywords-that-you-shouldne28099t-be-using/

Solution is to create multiple methods out the method with each method returning single value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check other methods as well. Example: TryToLoadDiscoverer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using ref and out in C#. Check this CA violation for more details.
Additional read: https://www.simplethread.com/ten-c-keywords-that-you-shouldne28099t-be-using/

Solution is to create multiple methods out the method with each method returning single value.

Reduced the ref usage. Only using in one place now.

Check other methods as well. Example: TryToLoadDiscoverer

TryDoSomework is very well used ways in BCL libraries. I would like to keep it as it is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using out keyword is not wrong but is not recommended. Please check above links for reasons. To get it cleared, what should be the recommended approach, we can have a second opinion. @cltshivash Can you recommend what should be the approach here?

ref double totalAdaptersUsed,
ref double totalTimeTakenByAdapters)
{
if (TryToLoadDiscoverer(discoverer, logger, out var discovererType) == false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: DiscovererEnumerator.TryToLoadDiscoverer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

ref double totalAdaptersUsed,
ref double totalTimeTakenByAdapters)
{
if (TryToLoadDiscoverer(discoverer, logger, out var discovererType) == false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TryToLoadDiscoverer already returns bool. No need for == false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

! is difficult to read. That's why kept false explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(!succuess) is more readable than if(success == false). We can have a second opinion here as well to know what is the recommended approach here.


// if instantiated successfully, get tests
try
this.testPlatformEventSource.AdapterDiscoveryStart(discoverer.Metadata.DefaultExecutorUri.AbsoluteUri);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: line spacing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see any.



/// <summary>
/// Looks up a localized string similar to No test is available for testcase filter `{0}` in {1}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test is available or No tests are available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test is available has been used in already existing resource string. To keep it consistency keeping it as it is.

{
internal static string ShortenTestCaseFilterIfRequired(string testCaseFilter)
{
var maxLength = 256;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move it to class const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


if (testCaseFilter.Length > maxLength)
{
shortenTestCaseFilter = testCaseFilter.Substring(0, maxLength) + "...";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use ternary operator here as if else contains single line of code.
return testCaseFilter.Length > maxLength ? testCaseFilter.Substring(0, maxLength) + "..." : testCaseFilter OR
return testCaseFilter.Substring(0, Math.Min(testCaseFilter.Length, maxLength))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better readability not using terninary operator.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That what case ternary operator should be used?
Ternary operators are useful for such scenarios only where if and else conditions have single lines

// Register for the discovery events.
events.DiscoveryMessage += this.TestMessageHandler;

// TODO Get changes from https://github.com/Microsoft/vstest/pull/1111/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a tracking item for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reopened the PR

@@ -236,7 +238,7 @@ private void TestRunRequest_OnRunCompletion(object sender, TestRunCompleteEventA
var testsFoundInAnySource = (e.TestRunStatistics == null) ? false : (e.TestRunStatistics.ExecutedTests > 0);

// Indicate the user to use testadapterpath command if there are no tests found
if (!testsFoundInAnySource && string.IsNullOrEmpty(CommandLineOptions.Instance.TestAdapterPath))
if (!testsFoundInAnySource && string.IsNullOrEmpty(CommandLineOptions.Instance.TestAdapterPath) && this.commandLineOptions.TestCaseFilterValue == null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string.IsNullOrEmpty instead of == null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestCaseFilterValue can't be empty because we won't accept empty value.

Copy link
Contributor

@abhishkk abhishkk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with suggestions

@smadala
Copy link
Contributor Author

smadala commented Jun 25, 2018

@abhishkk As suggestions are around personal choices of nits. I'm going ahead with merge. Will create another PR if required.

@smadala smadala merged commit e0caba4 into microsoft:master Jun 25, 2018
@smadala smadala deleted the fix-no-tests-message-on-filter branch June 25, 2018 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants