Bug 429959 - [tests] create unit tests for "Developer Statistics"
Summary: [tests] create unit tests for "Developer Statistics"
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Recommenders.incubator (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Timur Achmetow CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2014-03-09 09:25 EDT by Timur Achmetow CLA
Modified: 2019-07-24 14:36 EDT (History)
2 users (show)

See Also:


Attachments
Test class for DateFormatter (1.14 KB, text/plain)
2014-03-09 14:44 EDT, Timur Achmetow CLA
no flags Details
New Version of Test (1.85 KB, text/plain)
2014-03-10 18:45 EDT, Akif Etkue CLA
no flags Details
Extended Version of Formatter (1.35 KB, text/plain)
2014-03-10 18:46 EDT, Akif Etkue CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Timur Achmetow CLA 2014-03-09 09:25:17 EDT
The bundle "Developer Statistics" need some unit tests, which checks the internal logic. 
I have looked, which classes could be covered through some unit tests. The list see here: 

* TriggeredCommandCollector
* ExtensionPointReader
* DateFormatter
* TableSorters

For this class we have to create some unit tests.
Comment 1 Timur Achmetow CLA 2014-03-09 09:29:09 EDT
After the unit tests we could create also some UI tests. 
Before we start with the UI tests, we have to check out SWTBot and the build integration with maven (include SWTBot to our automated maven build). 

If the integration will be successful finished, we could write some SWTBot tests, which checks for example the internal logic of the TableViewers (loading data etc.).  
If we have done this step, please contact me again.
Comment 2 Timur Achmetow CLA 2014-03-09 09:38:26 EDT
The associated test plugin: o.e.r.stats.rcp.tests
Comment 3 Akif Etkue CLA 2014-03-09 09:43:42 EDT
(In reply to Timur Achmetow from comment #0)
> The bundle "Developer Statistics" need some unit tests, which checks the
> internal logic. 
> I have looked, which classes could be covered through some unit tests. The
> list see here: 
> 
> * TriggeredCommandCollector
> * ExtensionPointReader
> * DateFormatter
> * TableSorters
> 
> For this class we have to create some unit tests.

That sounds good, I will try this in the next few days.
Comment 4 Timur Achmetow CLA 2014-03-09 14:44:42 EDT
Created attachment 240697 [details]
Test class for DateFormatter

I have created some small unit tests for the class DateFormatter.
Comment 5 Timur Achmetow CLA 2014-03-09 14:47:18 EDT
(In reply to comment #3)
> That sounds good, I will try this in the next few days.

I have created a small example for the unit tests, see attachment.
Comment 6 Andreas Sewe CLA 2014-03-09 15:29:39 EDT
(In reply to Timur Achmetow from comment #5)
> (In reply to comment #3)
> > That sounds good, I will try this in the next few days.
> 
> I have created a small example for the unit tests, see attachment.

Timur, can you also guide Akif through the whole Gerrit process please. Best to get prospective students acquainted with that as quickly as possible. Thanks.
Comment 7 Timur Achmetow CLA 2014-03-09 15:42:11 EDT
(In reply to comment #6)
> Timur, can you also guide Akif through the whole Gerrit process please. Best to
> get prospective students acquainted with that as quickly as possible. Thanks.

Yes of course, Akif have at the moment some problems with Gerrit. He will try to fix the problem.
Comment 8 Akif Etkue CLA 2014-03-10 09:37:52 EDT
(In reply to Timur Achmetow from comment #7)
> Yes of course, Akif have at the moment some problems with Gerrit. He will
> try to fix the problem.

Yes that's right, I give my best.
Comment 9 Akif Etkue CLA 2014-03-10 18:45:38 EDT
Created attachment 240731 [details]
New Version of Test
Comment 10 Akif Etkue CLA 2014-03-10 18:46:22 EDT
Created attachment 240732 [details]
Extended Version of Formatter
Comment 11 Akif Etkue CLA 2014-03-10 18:51:34 EDT
(In reply to comment #7)
> Yes of course, Akif have at the moment some problems with Gerrit. He will try to fix the problem.

After 2 hours fighting against the CLA (problems with the login, web interface), now it works :D
I have pushed my first change to Gerrit: https://git.eclipse.org/r/#/c/23167/
Comment 12 Andreas Sewe CLA 2014-03-11 03:58:47 EDT
(In reply to Akif Eddy from comment #11)
> After 2 hours fighting against the CLA (problems with the login, web
> interface), now it works :D
> I have pushed my first change to Gerrit: https://git.eclipse.org/r/#/c/23167/

Awesome. Thanks Akif.

We'll move discussion of the change comment over to Gerrit now to discuss the actual code.
Comment 13 Akif Etkue CLA 2014-03-12 16:50:26 EDT
I have created several tests for DateFormatter and a few for TableSorters (see at gerrit). 
The TableSorters tests are JUnit-Plugin-Tests. Is that okay for our build server?
Comment 14 Andreas Sewe CLA 2014-03-13 04:15:11 EDT
Yes, JUnit Plugin tests are fine for our build server. BTW, you can see what it does here: <https://hudson.eclipse.org/recommenders/job/stats.gerrit.master/>. Just click on "Console Output" for the build you are interested in.
Comment 15 Akif Etkue CLA 2014-03-13 04:32:52 EDT
(In reply to Andreas Sewe from comment #14)
> Yes, JUnit Plugin tests are fine for our build server.

Okay, that's great. Thank you.
Comment 16 Akif Etkue CLA 2014-03-23 11:04:16 EDT
The tests for the class "DateFormatter" are finished and merged, see here: https://git.eclipse.org/r/#/c/23167
Next test class: TableSorters.
Comment 17 Akif Etkue CLA 2014-03-23 11:06:29 EDT
New gerrit review see here: https://git.eclipse.org/r/#/c/23755/
Comment 18 Akif Etkue CLA 2014-04-03 14:46:52 EDT
@Tim: Have you a favorite for the next class?
Comment 19 Timur Achmetow CLA 2014-04-03 15:45:56 EDT
I have create a first test for the class ExtensionPointReader, 
see here: https://git.eclipse.org/r/#/c/24412/
Comment 20 Andreas Sewe CLA 2014-04-15 03:54:32 EDT
Test for ExtensionPointerReader merged.
Comment 21 Timur Achmetow CLA 2014-04-16 11:57:00 EDT
Next candidate for our tests: TriggeredCommandCollector
Comment 22 Timur Achmetow CLA 2014-04-18 15:40:58 EDT
(In reply to comment #21)
> Next candidate for our tests: TriggeredCommandCollector

Okay, I had a look on the class TriggeredCommandCollector and the logic of it. 

We have here the same problem like in the class ExtensionPointReader. The class is at the moment not good testable. 
We have to refactor it a little bit for better testing. 

I would move the two methods TriggeredCommandsView#loadModelFromWorkspace() and TriggeredCommandsView#buildViewerModel()
in the class TriggeredCommandCollector and make them "protected". Then we could test this both methods with unit tests. 

Another point would be the collecting of events from the workbench, see TriggeredCommandCollector.listener (IExecutionListener)
@Andreas: Is this testable with mockito btw. make it sense to test this (catching events and persist them)?
Comment 23 Timur Achmetow CLA 2014-04-18 15:57:44 EDT
(In reply to comment #22)
> I would move the two methods TriggeredCommandsView#loadModelFromWorkspace() and
> TriggeredCommandsView#buildViewerModel()
> in the class TriggeredCommandCollector and make them "protected". Then we could
> test this both methods with unit tests.

Change for this stuff is online: https://git.eclipse.org/r/25292
Comment 24 Akif Etkue CLA 2014-04-20 07:25:31 EDT
(In reply to Timur Achmetow from comment #23)
> Change for this stuff is online: https://git.eclipse.org/r/25292

Great. I would continue the work on this change.
Comment 25 Andreas Sewe CLA 2014-04-22 03:36:36 EDT
(In reply to Timur Achmetow from comment #22)
> Another point would be the collecting of events from the workbench, see
> TriggeredCommandCollector.listener (IExecutionListener)
> @Andreas: Is this testable with mockito btw. make it sense to test this
> (catching events and persist them)?

It's certainly worth testing, yes. I wouldn't test the TriggeredCommandCollector itself (too much dependence on static Platform* methods and very little code), though, but the IExecutionListener.

Move the IExecutionListener to its own class and test that by calling preExecute from you test code.

To ease testing, I would also refrain from hard-coding the storage location in the IExecutionListener. At the very least, pass in a File to its constructor. Even better, though, would be to pass in a new StatisticsService that's responsible for persisting stuff on disk. The current design (one class writes to a file, another class reads from it) is unfortunate (and not thread-safe).
Comment 26 Akif Etkue CLA 2014-05-08 17:42:21 EDT
(In reply to Andreas Sewe from comment #25)
> It's certainly worth testing, yes. I wouldn't test the
> TriggeredCommandCollector itself (too much dependence on static Platform*
> methods and very little code), though, but the IExecutionListener.
> 
> Move the IExecutionListener to its own class and test that by calling
> preExecute from you test code.
> 
> To ease testing, I would also refrain from hard-coding the storage location
> in the IExecutionListener. At the very least, pass in a File to its
> constructor. Even better, though, would be to pass in a new
> StatisticsService that's responsible for persisting stuff on disk. The
> current design (one class writes to a file, another class reads from it) is
> unfortunate (and not thread-safe).

Change is online: https://git.eclipse.org/r/#/c/25934/