-
-
Notifications
You must be signed in to change notification settings - Fork 8
Add DataRow attribute allowing to have test cases in test methods using attributes #158
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
09b31b7
Providing inline data into test method.
torbacz e4dd94b
Merge branch 'main' into dataRowSupport
torbacz 8185076
Fix code style.
torbacz 39e12b2
Intellisence comments + comments + headers
torbacz 34f2155
PoC data row example.
torbacz 9d0e1b3
Update source/TestFrameworkShared/Helper.cs
josesimoes 9cc7eef
Update source/TestFrameworkShared/DataRowAttribute.cs
josesimoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // | ||
| // Copyright (c) .NET Foundation and Contributors | ||
| // Portions Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // See LICENSE file in the project root for full license information. | ||
| // | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Threading; | ||
|
|
||
| namespace nanoFramework.TestFramework.Test | ||
| { | ||
| [TestClass] | ||
| public class TestOfDataRow | ||
| { | ||
| [DataRow(1, 2, 3)] | ||
| [DataRow(5, 6, 11)] | ||
| public void TestAddition(int number1, int number2, int result) | ||
| { | ||
| var additionResult = number1 + number2; | ||
|
|
||
| Assert.Equal(additionResult, result); | ||
| } | ||
|
|
||
| [DataRow("TestString")] | ||
| public void TestString(string testData) | ||
| { | ||
| Assert.Equal(testData, "TestString"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <packages> | ||
| <package id="nanoFramework.CoreLibrary" version="1.11.7" targetFramework="netnanoframework10" /> | ||
| <package id="nanoFramework.Runtime.Native" version="1.5.2-preview.6" targetFramework="netnanoframework10" /> | ||
| <package id="nanoFramework.CoreLibrary" version="1.12.0" targetFramework="netnanoframework10" /> | ||
| <package id="nanoFramework.Runtime.Native" version="1.5.4" targetFramework="netnanoframework10" /> | ||
| </packages> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // | ||
| // Copyright (c) .NET Foundation and Contributors | ||
| // Portions Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // See LICENSE file in the project root for full license information. | ||
| // | ||
|
|
||
| using System; | ||
|
|
||
| namespace nanoFramework.TestFramework | ||
| { | ||
| /// <summary> | ||
| /// Data row attribute. Used for passing multiple parameters into same test method. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] | ||
| public class DataRowAttribute : Attribute | ||
josesimoes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| /// <summary> | ||
| /// Array containing all passed parameters | ||
| /// </summary> | ||
| public object[] MethodParameters { get; } | ||
josesimoes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the DataRowAttribute class. | ||
| /// </summary> | ||
| /// <param name="methodParameters">Parameters which should be stored for future execution of test method</param> | ||
| /// <exception cref="ArgumentNullException">Thrown when methodParameters is null</exception> | ||
| /// <exception cref="ArgumentException">Thrown when methodParameters is empty</exception> | ||
| public DataRowAttribute(params object[] methodParameters) | ||
josesimoes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| if (methodParameters == null) | ||
josesimoes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| throw new ArgumentNullException($"{nameof(methodParameters)} can not be null"); | ||
| } | ||
|
|
||
| if (methodParameters.Length == 0) | ||
josesimoes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| throw new ArgumentException($"{nameof(methodParameters)} can not be empty"); | ||
| } | ||
|
|
||
| MethodParameters = methodParameters; | ||
| } | ||
| } | ||
| } | ||
josesimoes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // | ||
| // Copyright (c) .NET Foundation and Contributors | ||
| // Portions Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // See LICENSE file in the project root for full license information. | ||
| // | ||
|
|
||
| using System.Reflection; | ||
|
|
||
| namespace nanoFramework.TestFramework | ||
| { | ||
| /// <summary> | ||
| /// Helper class for keeping test name same in TestAdapter and TestRunner | ||
| /// </summary> | ||
| public static class Helper | ||
josesimoes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| private static string GetJoinedParams(object[] data) | ||
| { | ||
| var returnString = string.Empty; | ||
| foreach (var item in data) | ||
josesimoes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| returnString += $"{item} | "; | ||
| } | ||
|
|
||
| // In each loop iteration we are appending " | " event at the end | ||
| // To keep return string clean, we are removing last 3 charcters | ||
| // Lenght starts from 1, substring from 0 | ||
| // To remove 3 last characters using this method, we need to add 1 | ||
| return returnString.Substring(0, returnString.Length - 4); | ||
Ellerbach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// Generates test display name based on passed <paramref name="method"/> and <paramref name="attribute"/>. | ||
| /// </summary> | ||
| /// <returns>Returns method name with parameters if passed attribute is of DataRow type</returns> | ||
| public static string GetTestDisplayName(MethodInfo method, object attribute) | ||
| { | ||
| // Comparing via full name, because attribute parameter is from "TestFramework.dll" | ||
| // and current type TestCaseAttribute is in scope of "TestAdapter" due to shared project | ||
| // The same reason - reflection to get value | ||
| if (attribute.GetType().FullName == typeof(DataRowAttribute).FullName) | ||
| { | ||
| var methodParameters = (object[])attribute.GetType() | ||
| .GetMethod($"get_{nameof(DataRowAttribute.MethodParameters)}").Invoke(attribute, null); | ||
|
|
||
| return $"{method.Name} - (params: {GetJoinedParams(methodParameters)})"; | ||
| } | ||
|
|
||
| return method.Name; | ||
| } | ||
| } | ||
| } | ||
josesimoes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.