Skip to content

Commit 9fca86e

Browse files
committed
Added sample slicing script and tests.
1 parent 7a3253e commit 9fca86e

6 files changed

+257
-0
lines changed

ParallelTestingSample-dotnet.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28010.2050
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SliceTests", "SliceTests\SliceTests.csproj", "{EEDC36D8-D8EE-494A-81CE-308D12BEC3ED}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{EEDC36D8-D8EE-494A-81CE-308D12BEC3ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EEDC36D8-D8EE-494A-81CE-308D12BEC3ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EEDC36D8-D8EE-494A-81CE-308D12BEC3ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EEDC36D8-D8EE-494A-81CE-308D12BEC3ED}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {3D9244A3-E98F-4BE6-B172-457815363931}
24+
EndGlobalSection
25+
EndGlobal

SliceTests/SliceTests.cs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Collections;
2+
using System.IO;
3+
using FluentAssertions;
4+
using NUnit.Framework;
5+
using OpenQA.Selenium.Chrome;
6+
7+
namespace SliceTests
8+
{
9+
public class SliceTests
10+
{
11+
private static IEnumerable Words()
12+
{
13+
using (var reader = new StreamReader("./testdata/words.txt"))
14+
{
15+
while (reader.Peek() >= 0)
16+
{
17+
var word = reader.ReadLine();
18+
yield return new TestCaseData(word).SetName("{m}_" + word);
19+
}
20+
}
21+
}
22+
23+
private ChromeDriver _webDriver;
24+
25+
[SetUp]
26+
public void Setup()
27+
{
28+
var options = new ChromeOptions();
29+
options.AddArguments("--headless", "--no-sandbox", "--disable-dev-shm-usage");
30+
31+
_webDriver = new ChromeDriver(Directory.GetCurrentDirectory(), options);
32+
}
33+
34+
[TearDown]
35+
public void TearDown()
36+
{
37+
_webDriver.Quit();
38+
}
39+
40+
[Test]
41+
[TestCaseSource(nameof(Words))]
42+
public void SearchTest_ByWord_ContainsInTitle(string word)
43+
{
44+
// Act
45+
_webDriver.Url = $"https://www.google.co.jp/search?q={word}";
46+
47+
// Assert
48+
var title = _webDriver.Title;
49+
title.Should().Contain(word).And.Contain("Google");
50+
}
51+
}
52+
}

SliceTests/SliceTests.csproj

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<None Update="testdata\words.txt">
11+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
12+
</None>
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="FluentAssertions" Version="5.5.1" />
17+
<PackageReference Include="nunit" Version="3.11.0" />
18+
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
19+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
20+
<PackageReference Include="Selenium.Support" Version="3.141.0" />
21+
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
22+
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="2.43.0" />
23+
</ItemGroup>
24+
25+
</Project>

SliceTests/testdata/words.txt

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
bird
2+
notice
3+
banish
4+
physical
5+
rough
6+
minority
7+
elect
8+
reference
9+
cry
10+
cycle
11+
cold
12+
enthusiasm
13+
chimpanzee
14+
project
15+
premature
16+
scramble
17+
module
18+
crop
19+
air
20+
false
21+
chord
22+
ghost
23+
key
24+
formulate
25+
captivate
26+
necklace
27+
neighbour
28+
result
29+
rear
30+
plug
31+
hardship
32+
graze
33+
young
34+
content
35+
hostility
36+
claim
37+
value
38+
retailer
39+
intensify
40+
environmental
41+
touch
42+
cherry
43+
panel
44+
learn
45+
effect
46+
omission
47+
silk
48+
possibility
49+
race
50+
reduction
51+
threaten
52+
council
53+
snow
54+
column
55+
prospect
56+
swell
57+
sign
58+
railroad
59+
trench
60+
financial
61+
stress
62+
duke
63+
conductor
64+
frank
65+
push
66+
coerce
67+
sand
68+
family
69+
stick
70+
chocolate
71+
user
72+
update
73+
attractive
74+
attitude
75+
stock
76+
strategic
77+
theory
78+
book
79+
royalty
80+
foundation
81+
orientation
82+
multimedia
83+
decay
84+
utter
85+
joke
86+
discrimination
87+
funny
88+
prejudice
89+
inside
90+
anticipation
91+
distance
92+
van
93+
deprive
94+
landscape
95+
commission
96+
railcar
97+
confine
98+
like
99+
marine
100+
microphone

azure-pipelines.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
jobs:
2+
- job: 'ParallelTesting'
3+
pool:
4+
name: Hosted Ubuntu 1604
5+
strategy:
6+
parallel: 5
7+
displayName: Run tests in parallel
8+
9+
steps:
10+
- task: DotNetCoreCLI@2
11+
displayName: Build
12+
inputs:
13+
command: build
14+
projects: '**/*.csproj'
15+
16+
- bash: |
17+
tests=($(dotnet test . --no-build --list-tests | grep Test_))
18+
. 'create_slicing_filter_condition.sh' $tests
19+
displayName: 'Create slicing filter condition'
20+
21+
- bash: |
22+
echo "Slicing filter condition: $(targetTestsFilter)"
23+
displayName: 'Echo slicing filter condition'
24+
25+
- task: DotNetCoreCLI@2
26+
displayName: Test
27+
inputs:
28+
command: test
29+
projects: '**/*Tests/*Tests.csproj'
30+
arguments: '--no-build --filter "$(targetTestsFilter)"'

create_slicing_filter_condition.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
filterProperty="Name"
4+
5+
tests=$1
6+
testCount=${#tests[@]}
7+
totalAgents=$SYSTEM_TOTALJOBSINPHASE
8+
agentNumber=$SYSTEM_JOBPOSITIONINPHASE
9+
10+
if [ $totalAgents -eq 0 ]; then totalAgents=1; fi
11+
if [ -z "$agentNumber" ]; then agentNumber=1; fi
12+
13+
echo "Total agents: $totalAgents"
14+
echo "Agent number: $agentNumber"
15+
echo "Total tests: $testCount"
16+
17+
echo "Target tests:"
18+
for ((i=$agentNumber; i <= $testCount;i=$((i+$totalAgents)))); do
19+
targetTestName=${tests[$i -1]}
20+
echo "$targetTestName"
21+
filter+="|${filterProperty}=${targetTestName}"
22+
done
23+
filter=${filter#"|"}
24+
25+
echo "##vso[task.setvariable variable=targetTestsFilter]$filter"

0 commit comments

Comments
 (0)