Test Data Supplier - modern entity-driven DataProvider alternative

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Test Data Supplier - modern entity-driven DataProvider alternative

Sergey Korol
Hi folks,

I'm working with TestNG for N years. It's a great framework, which helps me a lot in my daily activities. However, there're some areas which would be nice to improve, IMHO. Unfortunately, some mysterious circumstances still prevent TestNG from being updated to Java 8 (at least). And I don't really want to discuss it... again.

Anyway, I want to share a new Java 8 library - test-data-supplier, which is a DataProvider wrapper. It allows working with test data in a modern, user-friendly way. You can read more info on GitHub. But here's a quick features' overview:

A new DataSupplier annotation, which is a replacement for the common DataProvider, supports the following return types:
  • Collection
  • Map
  • Entry
  • Object[]
  • double[]
  • int[]
  • long[]
  • Stream / StreamEx
  • Tuple
  • A single Object of any common or custom type
It means that you can work with Java entities without bothering yourself about Object arrays or Iterators conversions.

@DataSupplier
public StreamEx<User> getRandomUsers() {
   
return StreamEx.generate(User::new).limit(10);
}

Moreover, you can still specify dataProvider arg on Test annotation level the same way you did before. Just refer to DataSupplier method.

@Test(dataProvider = "getRandomUsers")
public void shouldSupplyRandomUsers(final User user) {
   
// ...
}

Sometimes it's required to supply data as a single row on a single iteration. And that's what transpose flag does:

@DataSupplier(transpose = true)
public Tuple getExternalCollectionData() {
   
return Tuple.of(1, false, "data");
}

@Test(dataProviderClass = ExternalDataSuppliers.class, dataProvider = "getExternalCollectionData")
public void supplyExternalCollectionData(final int ob1, final boolean ob2, final String ob3) {
   
// ...
}

There could be even trickier cases when we receive data from external data source in a specific format, and want to flatten it. That's where flatMap flag may help:

@DataSupplier(flatMap = true)
public Map<Integer, String> getInternallyExtractedMapData() {
   
return EntryStream.of(asList("data1", "data2")).toMap();
}

@Test(dataProvider = "getInternallyExtractedMapData")
public void supplyInternallyExtractedMapData(final Integer key, final String value) {
   
// ...
}

In this case corresponding test will be executed twice. But on each iteration its internal Entry will be flatten into 2 standalone args.

Note that DataSupplier also supports name and runInParallel flags to make it similar to the original DataProvider.

You can find more details on GitHub. This library is published both to maven and jcenter. Some QAs in our local community have already tried it on Java 8 and Kotlin and gave a very positive feedback. There's also an IntelliJ IDEA plugin, which replaces common DataProvider inspections with a new alternative.

Would be greatly appreciated you thoughts, comments and suggestions.

Thanks,
Sergey

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

⇜Krishnan Mahadevan⇝
Sergey,

I wasn't able to find references to working with indices using this new model. Can you please help point me to a sample which shows that as well in action ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Fri, Nov 3, 2017 at 2:19 PM, Sergey Korol <[hidden email]> wrote:
Hi folks,

I'm working with TestNG for N years. It's a great framework, which helps me a lot in my daily activities. However, there're some areas which would be nice to improve, IMHO. Unfortunately, some mysterious circumstances still prevent TestNG from being updated to Java 8 (at least). And I don't really want to discuss it... again.

Anyway, I want to share a new Java 8 library - test-data-supplier, which is a DataProvider wrapper. It allows working with test data in a modern, user-friendly way. You can read more info on GitHub. But here's a quick features' overview:

A new DataSupplier annotation, which is a replacement for the common DataProvider, supports the following return types:
  • Collection
  • Map
  • Entry
  • Object[]
  • double[]
  • int[]
  • long[]
  • Stream / StreamEx
  • Tuple
  • A single Object of any common or custom type
It means that you can work with Java entities without bothering yourself about Object arrays or Iterators conversions.

@DataSupplier
public StreamEx<User> getRandomUsers() {
   
return StreamEx.generate(User::new).limit(10);
}

Moreover, you can still specify dataProvider arg on Test annotation level the same way you did before. Just refer to DataSupplier method.

@Test(dataProvider = "getRandomUsers")
public void shouldSupplyRandomUsers(final User user) {
   
// ...
}

Sometimes it's required to supply data as a single row on a single iteration. And that's what transpose flag does:

@DataSupplier(transpose = true)
public Tuple getExternalCollectionData() {
   
return Tuple.of(1, false, "data");
}

@Test(dataProviderClass = ExternalDataSuppliers.class, dataProvider = "getExternalCollectionData")
public void supplyExternalCollectionData(final int ob1, final boolean ob2, final String ob3) {
   
// ...
}

There could be even trickier cases when we receive data from external data source in a specific format, and want to flatten it. That's where flatMap flag may help:

@DataSupplier(flatMap = true)
public Map<Integer, String> getInternallyExtractedMapData() {
   
return EntryStream.of(asList("data1", "data2")).toMap();
}

@Test(dataProvider = "getInternallyExtractedMapData")
public void supplyInternallyExtractedMapData(final Integer key, final String value) {
   
// ...
}

In this case corresponding test will be executed twice. But on each iteration its internal Entry will be flatten into 2 standalone args.

Note that DataSupplier also supports name and runInParallel flags to make it similar to the original DataProvider.

You can find more details on GitHub. This library is published both to maven and jcenter. Some QAs in our local community have already tried it on Java 8 and Kotlin and gave a very positive feedback. There's also an IntelliJ IDEA plugin, which replaces common DataProvider inspections with a new alternative.

Would be greatly appreciated you thoughts, comments and suggestions.

Thanks,
Sergey

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

Sergey Korol
Hi Krishnan,

I haven't added indices support, as the same functionality could be achieved with streams, e.g.:

EntryStream.of(someList).filterKeys(i -> yourCondition).values();

Let me know if you have some specific cases, when streams won't help with filtering, please.

Thanks,
Sergey 

On Friday, November 3, 2017 at 12:50:55 PM UTC+2, Krishnan Mahadevan wrote:
Sergey,

I wasn't able to find references to working with indices using this new model. Can you please help point me to a sample which shows that as well in action ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/
My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

On Fri, Nov 3, 2017 at 2:19 PM, Sergey Korol <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VYxuL1CeBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">serhii....@...> wrote:
Hi folks,

I'm working with TestNG for N years. It's a great framework, which helps me a lot in my daily activities. However, there're some areas which would be nice to improve, IMHO. Unfortunately, some mysterious circumstances still prevent TestNG from being updated to Java 8 (at least). And I don't really want to discuss it... again.

Anyway, I want to share a new Java 8 library - <a href="https://github.com/sskorol/test-data-supplier" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fsskorol%2Ftest-data-supplier\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFMFTXDxFH9I-QcszGonwGCg30lxw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fsskorol%2Ftest-data-supplier\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFMFTXDxFH9I-QcszGonwGCg30lxw&#39;;return true;">test-data-supplier, which is a DataProvider wrapper. It allows working with test data in a modern, user-friendly way. You can read more info on GitHub. But here's a quick features' overview:

A new DataSupplier annotation, which is a replacement for the common DataProvider, supports the following return types:
  • Collection
  • Map
  • Entry
  • Object[]
  • double[]
  • int[]
  • long[]
  • Stream / StreamEx
  • Tuple
  • A single Object of any common or custom type
It means that you can work with Java entities without bothering yourself about Object arrays or Iterators conversions.

@DataSupplier
public StreamEx<User> getRandomUsers() {
   
return StreamEx.generate(User::new).limit(10);
}

Moreover, you can still specify dataProvider arg on Test annotation level the same way you did before. Just refer to DataSupplier method.

@Test(dataProvider = "getRandomUsers")
public void shouldSupplyRandomUsers(final User user) {
   
// ...
}

Sometimes it's required to supply data as a single row on a single iteration. And that's what transpose flag does:

@DataSupplier(transpose = true)
public Tuple getExternalCollectionData() {
   
return Tuple.of(1, false, "data");
}

@Test(dataProviderClass = ExternalDataSuppliers.class, dataProvider = "getExternalCollectionData")
public void supplyExternalCollectionData(final int ob1, final boolean ob2, final String ob3) {
   
// ...
}

There could be even trickier cases when we receive data from external data source in a specific format, and want to flatten it. That's where flatMap flag may help:

@DataSupplier(flatMap = true)
public Map<Integer, String> getInternallyExtractedMapData() {
   
return EntryStream.of(asList("data1", "data2")).toMap();
}

@Test(dataProvider = "getInternallyExtractedMapData")
public void supplyInternallyExtractedMapData(final Integer key, final String value) {
   
// ...
}

In this case corresponding test will be executed twice. But on each iteration its internal Entry will be flatten into 2 standalone args.

Note that DataSupplier also supports name and runInParallel flags to make it similar to the original DataProvider.

You can find more details on <a href="https://github.com/sskorol/test-data-supplier" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fsskorol%2Ftest-data-supplier\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFMFTXDxFH9I-QcszGonwGCg30lxw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fsskorol%2Ftest-data-supplier\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFMFTXDxFH9I-QcszGonwGCg30lxw&#39;;return true;">GitHub. This library is published both to maven and jcenter. Some QAs in our local community have already tried it on Java 8 and Kotlin and gave a very positive feedback. There's also an IntelliJ IDEA <a href="https://github.com/sskorol/test-data-supplier-plugin" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fsskorol%2Ftest-data-supplier-plugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEvvLTqSOS01J1qRNzf1kVlO4vppA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fsskorol%2Ftest-data-supplier-plugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEvvLTqSOS01J1qRNzf1kVlO4vppA&#39;;return true;">plugin, which replaces common DataProvider inspections with a new alternative.

Would be greatly appreciated you thoughts, comments and suggestions.

Thanks,
Sergey

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VYxuL1CeBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VYxuL1CeBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

⇜Krishnan Mahadevan⇝
Sergei,

I haven't figured out streams completely. So please bear with me if this sounds naive.

I was wondering how do I select a few items in a List/Array based on indices using streams?
Using indices I can choose random locations within the List/Array and let TestNG just handpick those values alone.
I am not sure how I would be able to specify them as a Predicate to enable filtering.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Fri, Nov 3, 2017 at 5:03 PM, Sergey Korol <[hidden email]> wrote:
Hi Krishnan,

I haven't added indices support, as the same functionality could be achieved with streams, e.g.:

EntryStream.of(someList).filterKeys(i -> yourCondition).values();

Let me know if you have some specific cases, when streams won't help with filtering, please.

Thanks,
Sergey 

On Friday, November 3, 2017 at 12:50:55 PM UTC+2, Krishnan Mahadevan wrote:
Sergey,

I wasn't able to find references to working with indices using this new model. Can you please help point me to a sample which shows that as well in action ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Fri, Nov 3, 2017 at 2:19 PM, Sergey Korol <[hidden email]> wrote:
Hi folks,

I'm working with TestNG for N years. It's a great framework, which helps me a lot in my daily activities. However, there're some areas which would be nice to improve, IMHO. Unfortunately, some mysterious circumstances still prevent TestNG from being updated to Java 8 (at least). And I don't really want to discuss it... again.

Anyway, I want to share a new Java 8 library - test-data-supplier, which is a DataProvider wrapper. It allows working with test data in a modern, user-friendly way. You can read more info on GitHub. But here's a quick features' overview:

A new DataSupplier annotation, which is a replacement for the common DataProvider, supports the following return types:
  • Collection
  • Map
  • Entry
  • Object[]
  • double[]
  • int[]
  • long[]
  • Stream / StreamEx
  • Tuple
  • A single Object of any common or custom type
It means that you can work with Java entities without bothering yourself about Object arrays or Iterators conversions.

@DataSupplier
public StreamEx<User> getRandomUsers() {
   
return StreamEx.generate(User::new).limit(10);
}

Moreover, you can still specify dataProvider arg on Test annotation level the same way you did before. Just refer to DataSupplier method.

@Test(dataProvider = "getRandomUsers")
public void shouldSupplyRandomUsers(final User user) {
   
// ...
}

Sometimes it's required to supply data as a single row on a single iteration. And that's what transpose flag does:

@DataSupplier(transpose = true)
public Tuple getExternalCollectionData() {
   
return Tuple.of(1, false, "data");
}

@Test(dataProviderClass = ExternalDataSuppliers.class, dataProvider = "getExternalCollectionData")
public void supplyExternalCollectionData(final int ob1, final boolean ob2, final String ob3) {
   
// ...
}

There could be even trickier cases when we receive data from external data source in a specific format, and want to flatten it. That's where flatMap flag may help:

@DataSupplier(flatMap = true)
public Map<Integer, String> getInternallyExtractedMapData() {
   
return EntryStream.of(asList("data1", "data2")).toMap();
}

@Test(dataProvider = "getInternallyExtractedMapData")
public void supplyInternallyExtractedMapData(final Integer key, final String value) {
   
// ...
}

In this case corresponding test will be executed twice. But on each iteration its internal Entry will be flatten into 2 standalone args.

Note that DataSupplier also supports name and runInParallel flags to make it similar to the original DataProvider.

You can find more details on GitHub. This library is published both to maven and jcenter. Some QAs in our local community have already tried it on Java 8 and Kotlin and gave a very positive feedback. There's also an IntelliJ IDEA plugin, which replaces common DataProvider inspections with a new alternative.

Would be greatly appreciated you thoughts, comments and suggestions.

Thanks,
Sergey

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

Sergey Korol
Here's a quick sample:

// assuming you want to use the following indices
final IntStreamEx streamIndices = IntStreamEx.of(0, 2, 4);
final List<Integer> listIndices = asList(1, 3);


return EntryStream.of(asList("data1", "data2", "data3", "data4", "data5")) // original collection mapped with indices
                 
.filterKeys(streamIndices::has) // picks only 0, 2, 4 elements
                 
//.filterKeys(listIndices::contains) // picks only 1, 3 elements
                 
//.filterKeys(i -> i % 2 == 0) // e.g. for even numbers
                 
//.limit(2) // pick first 2
                 
//.skip(3) // skip first 3
                 
.values();

But if it's not quite obvious, I can add new indices arg. It won't be complicated.

On Friday, November 3, 2017 at 1:43:25 PM UTC+2, Krishnan Mahadevan wrote:
Sergei,

I haven't figured out streams completely. So please bear with me if this sounds naive.

I was wondering how do I select a few items in a List/Array based on indices using streams?
Using indices I can choose random locations within the List/Array and let TestNG just handpick those values alone.
I am not sure how I would be able to specify them as a Predicate to enable filtering.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/
My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

Sergey Korol
Short update: first line with streamIndices won't be working as expected within EntryStream. Forgot that has is a terminal operation, so stream will be closed after first iteration, and throw an exception on second. However, listIndices sample should work fine. Sorry for the confusion.

On Friday, November 3, 2017 at 5:01:13 PM UTC+2, Sergey Korol wrote:
Here's a quick sample:

// assuming you want to use the following indices
final IntStreamEx streamIndices = IntStreamEx.of(0, 2, 4);
final List<Integer> listIndices = asList(1, 3);


return EntryStream.of(asList("data1", "data2", "data3", "data4", "data5")) // original collection mapped with indices
                 
.filterKeys(streamIndices::has) // picks only 0, 2, 4 elements
                 
//.filterKeys(listIndices::contains) // picks only 1, 3 elements
                 
//.filterKeys(i -> i % 2 == 0) // e.g. for even numbers
                 
//.limit(2) // pick first 2
                 
//.skip(3) // skip first 3
                 
.values();

But if it's not quite obvious, I can add new indices arg. It won't be complicated.

On Friday, November 3, 2017 at 1:43:25 PM UTC+2, Krishnan Mahadevan wrote:
Sergei,

I haven't figured out streams completely. So please bear with me if this sounds naive.

I was wondering how do I select a few items in a List/Array based on indices using streams?
Using indices I can choose random locations within the List/Array and let TestNG just handpick those values alone.
I am not sure how I would be able to specify them as a Predicate to enable filtering.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/
My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

Sergey Korol
Krishnan,

I've just added native indices support on annotation level for you. 1.3.0 version is already published to jcenter. In 30 min should appear in maven as well.

Regards,
Sergey

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

⇜Krishnan Mahadevan⇝

Thanks Sergei. Appreciate the spontaneous turnaround

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

From: <[hidden email]> on behalf of Sergey Korol <[hidden email]>
Reply-To: <[hidden email]>
Date: Saturday, November 4, 2017 at 2:23 AM
To: testng-users <[hidden email]>
Subject: Re: [testng-users] Test Data Supplier - modern entity-driven DataProvider alternative

 

Krishnan,

 

I've just added native indices support on annotation level for you. 1.3.0 version is already published to jcenter. In 30 min should appear in maven as well.

 

Regards,

Sergey

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

Todd Bradley-2
In reply to this post by Sergey Korol
Super cool. Thanks, Sergey. TestNG could definitely stand to be modernized. What's next?

On Fri, Nov 3, 2017 at 2:49 AM, Sergey Korol <[hidden email]> wrote:
Hi folks,

I'm working with TestNG for N years. It's a great framework, which helps me a lot in my daily activities. However, there're some areas which would be nice to improve, IMHO. Unfortunately, some mysterious circumstances still prevent TestNG from being updated to Java 8 (at least). And I don't really want to discuss it... again.

Anyway, I want to share a new Java 8 library - test-data-supplier, which is a DataProvider wrapper. It allows working with test data in a modern, user-friendly way. You can read more info on GitHub. But here's a quick features' overview:

A new DataSupplier annotation, which is a replacement for the common DataProvider, supports the following return types:
  • Collection
  • Map
  • Entry
  • Object[]
  • double[]
  • int[]
  • long[]
  • Stream / StreamEx
  • Tuple
  • A single Object of any common or custom type
It means that you can work with Java entities without bothering yourself about Object arrays or Iterators conversions.

@DataSupplier
public StreamEx<User> getRandomUsers() {
   
return StreamEx.generate(User::new).limit(10);
}

Moreover, you can still specify dataProvider arg on Test annotation level the same way you did before. Just refer to DataSupplier method.

@Test(dataProvider = "getRandomUsers")
public void shouldSupplyRandomUsers(final User user) {
   
// ...
}

Sometimes it's required to supply data as a single row on a single iteration. And that's what transpose flag does:

@DataSupplier(transpose = true)
public Tuple getExternalCollectionData() {
   
return Tuple.of(1, false, "data");
}

@Test(dataProviderClass = ExternalDataSuppliers.class, dataProvider = "getExternalCollectionData")
public void supplyExternalCollectionData(final int ob1, final boolean ob2, final String ob3) {
   
// ...
}

There could be even trickier cases when we receive data from external data source in a specific format, and want to flatten it. That's where flatMap flag may help:

@DataSupplier(flatMap = true)
public Map<Integer, String> getInternallyExtractedMapData() {
   
return EntryStream.of(asList("data1", "data2")).toMap();
}

@Test(dataProvider = "getInternallyExtractedMapData")
public void supplyInternallyExtractedMapData(final Integer key, final String value) {
   
// ...
}

In this case corresponding test will be executed twice. But on each iteration its internal Entry will be flatten into 2 standalone args.

Note that DataSupplier also supports name and runInParallel flags to make it similar to the original DataProvider.

You can find more details on GitHub. This library is published both to maven and jcenter. Some QAs in our local community have already tried it on Java 8 and Kotlin and gave a very positive feedback. There's also an IntelliJ IDEA plugin, which replaces common DataProvider inspections with a new alternative.

Would be greatly appreciated you thoughts, comments and suggestions.

Thanks,
Sergey

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

Sergey Korol
Thanks Todd! What's next? We'll see. But tight Java 8 integration would be a great chance to get some fresh air.

On Saturday, November 4, 2017 at 2:55:43 PM UTC+2, Todd Bradley wrote:
Super cool. Thanks, Sergey. TestNG could definitely stand to be modernized. What's next?

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="7TbNCbTzBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="7TbNCbTzBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

Julien Herr
Hi Sergey,

Great job with your extension.

Don't hesitate to create issue if you need some core improvements which can help you to provide feature or avoid some reflection tricks :)

Julien

Le dimanche 5 novembre 2017 08:58:47 UTC+1, Sergey Korol a écrit :
Thanks Todd! What's next? We'll see. But tight Java 8 integration would be a great chance to get some fresh air.

On Saturday, November 4, 2017 at 2:55:43 PM UTC+2, Todd Bradley wrote:
Super cool. Thanks, Sergey. TestNG could definitely stand to be modernized. What's next?

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at <a href="https://groups.google.com/group/testng-users" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

Sergey Korol
Hi Julien,

Thanks! And I agree that sometimes it's better and easier to add some features directly to TestNG core.
However, I believe that release cycles should be more frequent to make features more valuable in such case.

You know, when people request some feature, they expect to get it within a reasonable time range.
6.12 version (which is not yet published to Maven Central) is a very good example to get an idea what I'm talking about.

Regards,
Sergey 

On Sunday, November 5, 2017 at 5:32:43 PM UTC+2, Julien Herr wrote:
Hi Sergey,

Great job with your extension.

Don't hesitate to create issue if you need some core improvements which can help you to provide feature or avoid some reflection tricks :)

Julien

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

sunny sachdeva
HI Sergey,

These new features looks very promising. I am going to try for sure. Thanks

On Monday, November 6, 2017 at 12:24:55 PM UTC+5:30, Sergey Korol wrote:
Hi Julien,

Thanks! And I agree that sometimes it's better and easier to add some features directly to TestNG core.
However, I believe that release cycles should be more frequent to make features more valuable in such case.

You know, when people request some feature, they expect to get it within a reasonable time range.
6.12 version (which is not yet published to Maven Central) is a very good example to get an idea what I'm talking about.

Regards,
Sergey 

On Sunday, November 5, 2017 at 5:32:43 PM UTC+2, Julien Herr wrote:
Hi Sergey,

Great job with your extension.

Don't hesitate to create issue if you need some core improvements which can help you to provide feature or avoid some reflection tricks :)

Julien

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

Julien Herr
In reply to this post by Sergey Korol
In fact, the idea is not to integrate your work in the core but to help you (and others) to provide great features on the top of TestNG.
Maybe some SPIs are currently missing.

Maven Central is another story :)
https://github.com/cbeust/testng/issues/1506

Le lundi 6 novembre 2017 07:54:55 UTC+1, Sergey Korol a écrit :
Hi Julien,

Thanks! And I agree that sometimes it's better and easier to add some features directly to TestNG core.
However, I believe that release cycles should be more frequent to make features more valuable in such case.

You know, when people request some feature, they expect to get it within a reasonable time range.
6.12 version (which is not yet published to Maven Central) is a very good example to get an idea what I'm talking about.

Regards,
Sergey 

On Sunday, November 5, 2017 at 5:32:43 PM UTC+2, Julien Herr wrote:
Hi Sergey,

Great job with your extension.

Don't hesitate to create issue if you need some core improvements which can help you to provide feature or avoid some reflection tricks :)

Julien

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

Sergey Korol
In reply to this post by sunny sachdeva
Hi Sunny,

Would be appreciated your feedback. Thanks.

On Monday, November 6, 2017 at 9:11:32 AM UTC+2, sunny sachdeva wrote:
HI Sergey,

These new features looks very promising. I am going to try for sure. Thanks

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

Sergey Korol
In reply to this post by Julien Herr
Got it. Sounds good. I'll check what could be added on TestNG level and create a feature request. Thanks.

On Monday, November 6, 2017 at 10:17:11 AM UTC+2, Julien Herr wrote:
In fact, the idea is not to integrate your work in the core but to help you (and others) to provide great features on the top of TestNG.
Maybe some SPIs are currently missing.

Maven Central is another story :)
<a href="https://github.com/cbeust/testng/issues/1506" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcbeust%2Ftestng%2Fissues%2F1506\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHn3pezTNfxnxZi06abUudBCTVqiA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fcbeust%2Ftestng%2Fissues%2F1506\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHn3pezTNfxnxZi06abUudBCTVqiA&#39;;return true;">https://github.com/cbeust/testng/issues/1506

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Test Data Supplier - modern entity-driven DataProvider alternative

Cédric Beust ♔-2

-- 
Cédric


On Mon, Nov 6, 2017 at 8:14 AM, Sergey Korol <[hidden email]> wrote:
Got it. Sounds good. I'll check what could be added on TestNG level and create a feature request. Thanks.

On Monday, November 6, 2017 at 10:17:11 AM UTC+2, Julien Herr wrote:
In fact, the idea is not to integrate your work in the core but to help you (and others) to provide great features on the top of TestNG.
Maybe some SPIs are currently missing.

Maven Central is another story :)

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.