Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 349998 - [test] JUnit tests for debug UI
Summary: [test] JUnit tests for debug UI
Status: RESOLVED FIXED
Alias: None
Product: TCF
Classification: Tools
Component: Debug (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 1.0.0   Edit
Assignee: Project Inbox CLA
QA Contact: Eugene Tarassov CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-22 00:42 EDT by Pawel Piech CLA
Modified: 2013-06-05 05:42 EDT (History)
3 users (show)

See Also:


Attachments
Plugin with sample unit test. (163.96 KB, application/x-download)
2011-06-22 00:42 EDT, Pawel Piech CLA
no flags Details
Patch for model proxy. (3.14 KB, patch)
2011-06-23 00:56 EDT, Pawel Piech CLA
no flags Details | Diff
Patch with updated tests. (130.31 KB, patch)
2011-12-14 13:36 EST, Pawel Piech CLA
eugene: iplog+
Details | Diff
Patch with updates. (190.83 KB, patch)
2012-01-09 14:07 EST, Pawel Piech CLA
mober.at+eclipse: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel Piech CLA 2011-06-22 00:42:35 EDT
Created attachment 198367 [details]
Plugin with sample unit test.

I began to pull together a framework for writing unit tests to validate the operation of debugger views (debug view, registers, variables, etc.).  I started by refactoring one of the connection diagnostics tests to run as a unit test and then I added tools to wait for and examine the contents of debug views.  There is a sample unit test (SampleTest) which exercises the framework.  

Do you see value in this approach?  Would it be difficult to hook up unit tests to run nightly for the TCF project?
Comment 1 Eugene Tarassov CLA 2011-06-22 14:58:26 EDT
The code looks good.

We certainly need tests for the debugger UI. It should not be difficult to hook up UI unit tests to run nightly.

Some notes:
1. In some places the test code calls TCF from a wrong thread. You need to run it with asserts enabled to see the failures - add -ea to JVM command line.
2. Latest version of TCFModelProxy has problems accessing virtual view, it expects the view to be based on TreeModelViewer and Tree control. Not sure what is the best way to resolve this.
Comment 2 Pawel Piech CLA 2011-06-23 00:56:41 EDT
Created attachment 198444 [details]
Patch for model proxy.

(In reply to comment #1)
Great.  I didn't think of the -ea, it's a small fix.  The model proxy could avoid using SWT, by using ITreeModelViewer and ITreeModelContentProvider interfaces.  They're both internal interfaces, but at least they're interfaces.  The attached patch does that and the tests pass ;-)

I'll look at creating some real tests next as I look at adding some real functionality.
Comment 3 Eugene Tarassov CLA 2011-06-24 00:30:41 EDT
I have committed model proxy patch.
Thanks!
Comment 4 Pawel Piech CLA 2011-12-14 13:36:37 EST
Created attachment 208399 [details]
Patch with updated tests.

I had updated the tests to run with lastest in master.  Unfortunately, it depends on the change in TCFModelProxy and on latest nightly build in Eclipse Platform.
Comment 5 Eugene Tarassov CLA 2011-12-15 17:15:12 EST
I have committed the code into juno-refactoring branch, into "tests" directory.
Note that master branch code is outdated, and current TCF development branch is juno-refactoring, which eventually (like in few weeks) will become a new master.

I have changed import statements to match new TCF package names.

However, the code still has a few build errors, which are caused by changes in org.eclipse.debug.ui internal APIs. I'm not sure how to fix those. Pawel, could you, please, have a look?
Comment 6 Pawel Piech CLA 2011-12-15 17:21:57 EST
(In reply to comment #5)

> I have committed the code into juno-refactoring branch, into "tests" directory.
> Note that master branch code is outdated, and current TCF development branch is
> juno-refactoring, which eventually (like in few weeks) will become a new
> master.
Thank you for merging the patch, it's nice for sharing the code, but I wonder if it's not a bit soon since I've only written a couple of proof of concept tests so far.  I'm currently looking at how to simplify the test framework a bit.

> However, the code still has a few build errors, which are caused by changes in
> org.eclipse.debug.ui internal APIs. I'm not sure how to fix those. Pawel, could
> you, please, have a look?
If it's in Juno-branch, could we make the build depend on Platform 3.8?  It would need to use the latest I-build though, since a couple of the changes I just checked in didn't make it into M4.
Comment 7 Eugene Tarassov CLA 2011-12-15 18:00:28 EST
(In reply to comment #6)
> (In reply to comment #5)
> 
> > I have committed the code into juno-refactoring branch, into "tests" directory.
> > Note that master branch code is outdated, and current TCF development branch is
> > juno-refactoring, which eventually (like in few weeks) will become a new
> > master.
> Thank you for merging the patch, it's nice for sharing the code, but I wonder
> if it's not a bit soon since I've only written a couple of proof of concept
> tests so far.  I'm currently looking at how to simplify the test framework a
> bit.

I don't see any problems with having experimental code in the repository, especially since it is a separate plugin. And the code is getting large, so it is going to be difficult to work with the code without a repository.

> 
> > However, the code still has a few build errors, which are caused by changes in
> > org.eclipse.debug.ui internal APIs. I'm not sure how to fix those. Pawel, could
> > you, please, have a look?
> If it's in Juno-branch, could we make the build depend on Platform 3.8?  It
> would need to use the latest I-build though, since a couple of the changes I
> just checked in didn't make it into M4.

I'm not sure what is the difference between Juno and Platform 3.8. Anyway, at least for main TCF plugins, I'd like to maintain compatibility with latest Eclipse release (currently 3.7.1), and use Java introspection tricks if necessary. But the tests plugin, of course, can require the very latest code. It can even depend on building org.eclipse.debug.ui from source - it's OK.
Comment 8 Pawel Piech CLA 2011-12-15 19:11:31 EST
(In reply to comment #7)
Makes sense, I'll put together another patch for TCFModelProxy so it'd work with tests, 3.7.x and 3.8.  

Juno is just the name for the release train that includes platform 3.8.  But I guess that even for TCF that's released on the Juno train, we'd like it to work with platform 3.7.
Comment 9 Pawel Piech CLA 2012-01-09 14:07:41 EST
Created attachment 209225 [details]
Patch with updates.

I've been refactoring the initial test framework to use acpm for the test procedures.  In order to make it work I had to invest in making the cache managers.  As we discussed on mailing list, I probably spent a bit too much time in the cache resetting logic, but I it was still an interesting exercise.  Please let me know what you think.

The patch is against juno-refactoring branch.
Comment 10 Eugene Tarassov CLA 2012-01-09 16:18:45 EST
The code looks cool.

I have one question: you wrap into cache items results of commands like ICache<Object> suspend(). It looks redundant - such cache items expire immediately and cannot be re-validated, because the command changes the target state. Why do you need such cache items?
Comment 11 Pawel Piech CLA 2012-01-09 16:37:39 EST
(In reply to comment #10)
> The code looks cool.
> 
> I have one question: you wrap into cache items results of commands like
> ICache<Object> suspend(). It looks redundant - such cache items expire
> immediately and cannot be re-validated, because the command changes the target
> state. Why do you need such cache items?

I just wanted to stuff more operations into a single transaction to make the overall code more readable.  For test purposes I'm not worried about the cache map growing unbound since the tests are short and maps are reset after every test.
Comment 12 Eugene Tarassov CLA 2012-01-09 17:35:33 EST
(In reply to comment #11)
> (In reply to comment #10)
> > The code looks cool.
> > 
> > I have one question: you wrap into cache items results of commands like
> > ICache<Object> suspend(). It looks redundant - such cache items expire
> > immediately and cannot be re-validated, because the command changes the target
> > state. Why do you need such cache items?
> 
> I just wanted to stuff more operations into a single transaction to make the
> overall code more readable.  For test purposes I'm not worried about the cache
> map growing unbound since the tests are short and maps are reset after every
> test.

For me, it looks confusing. A transaction is usually defined as something you can rollback. But you cannot revert and then re-run commands like suspend (and especially resume). It's OK to conclude (or commit) a transaction with such command, but creating extra cache item for that seems unnecessary and confusing.

Anyway, I'd like to commit the patch. Is it OK with you?
Comment 13 Pawel Piech CLA 2012-01-09 17:49:21 EST
(In reply to comment #12)
> For me, it looks confusing. A transaction is usually defined as something you
> can rollback. But you cannot revert and then re-run commands like suspend (and
> especially resume). It's OK to conclude (or commit) a transaction with such
> command, but creating extra cache item for that seems unnecessary and
> confusing.

Good point about the terminology.  For test procedures the logic flow is usually something like: execute command/wait for condition/validate result then repeat, so being able to put it in one "transaction" is very convenient.  I also create caches to wait for events which is probably a little confusing as well.  But I doubt that this pattern would be useful for much outside of the tests, so I hope it won't be a problem. 

> Anyway, I'd like to commit the patch. Is it OK with you?

Yes, thank you :-)
Comment 14 Eugene Tarassov CLA 2012-01-09 17:56:12 EST
(In reply to comment #13)
> (In reply to comment #12)
> > For me, it looks confusing. A transaction is usually defined as something you
> > can rollback. But you cannot revert and then re-run commands like suspend (and
> > especially resume). It's OK to conclude (or commit) a transaction with such
> > command, but creating extra cache item for that seems unnecessary and
> > confusing.
> 
> Good point about the terminology.  For test procedures the logic flow is
> usually something like: execute command/wait for condition/validate result then
> repeat, so being able to put it in one "transaction" is very convenient.  I
> also create caches to wait for events which is probably a little confusing as
> well.  But I doubt that this pattern would be useful for much outside of the
> tests, so I hope it won't be a problem. 
> 
> > Anyway, I'd like to commit the patch. Is it OK with you?
> 
> Yes, thank you :-)

Committed.
Thanks.
Comment 15 Pawel Piech CLA 2012-01-26 00:53:38 EST
I made some updates to the test framework to allow testing of eclipse breakpoint integration.  My goal was to enable Scott to write tests to validate the logic he is contributing for relocating CDT breakpoints. 

Please pull the commit from https://github.com/wind-river-cdt/tcf/commit/0541f74b15b87745b3b7383af5a247f36cda1015
Comment 16 Eugene Tarassov CLA 2012-01-26 17:27:26 EST
(In reply to comment #15)
> I made some updates to the test framework to allow testing of eclipse
> breakpoint integration.  My goal was to enable Scott to write tests to validate
> the logic he is contributing for relocating CDT breakpoints. 
> 
> Please pull the commit from
> https://github.com/wind-river-cdt/tcf/commit/0541f74b15b87745b3b7383af5a247f36cda1015

Committed.
Thanks.
Comment 17 Martin Oberhuber CLA 2013-05-24 12:59:12 EDT
Comment on attachment 209225 [details]
Patch with updates.

iplog- since author is in git:

http://git.eclipse.org/c/tcf/org.eclipse.tcf.git/commit?id=58086538560ea8e6ac5f9f9c64f9f9f1eed506f4