0

We're executing Gherkin features/scenarios with SpecFlow by GUI automation with Selenium. The web server used is CassiniDev, as described in this SO answer.

A lot of scenarios (a.k.a. examples) include logic like:

Given the customer does something
When some time elapse
Then ...

How does one fake the system time for a system under test that runs in a separate process, like in our acceptance/specification by example tests described above?

(For ordinary unit/integration tests that are executed in the same process as the SUT, the fake system time issue is solved by using our own SystemDateTime type which allows us to change what is returned by Now() (a public lambda expr).)

Community
  • 1
  • 1
Martin R-L
  • 4,039
  • 3
  • 28
  • 28
  • 3
    You didn't ask a single question in your ... "question". Instead, you provided a solution to the question posed in the title of your question, which leaves us with 0 + 1 - 1 = 0 questions to answer ;-) – Daniel Hilgarth Feb 03 '12 at 13:06
  • The question is: "How to fake the system time for a system under test that runs in a separate process?" I'll add it to the body for added clarity. – Martin R-L Feb 03 '12 at 13:19
  • 2
    It doesn't add any clarity if you repeat the already solved question in the body of the question. You are solving the problem by using your own SystemDateTime type. This type doesn't depend on where the test runs - so what's the problem? – Daniel Hilgarth Feb 03 '12 at 13:24
  • The problem is that I'm starting a web server with a web site programmatically. The tests executes in a different process. How do I change the value of a static property in a different process (i.e. the process of the web site)? – Martin R-L Feb 03 '12 at 13:36
  • Now, the question is clear, thanks. – Daniel Hilgarth Feb 03 '12 at 13:43
  • 1
    @MartinR-L: Maybe you just need to modify the code responsible for handling `some time elapse` to set up your `SystemDateTime` object accordingly? – Igor Korkhov Feb 03 '12 at 13:46
  • @Samuel Slade I really liked the code tag you so kindly removed. The language is called Gherkin BTW. – Martin R-L Feb 03 '12 at 13:51
  • @MartinR-L: it's difficult to tell without looking at your code. I don't quite understand what your `when` clause actually does. – Igor Korkhov Feb 03 '12 at 13:52
  • @IgorKorkhov Right now, the When of the Gherkin above does nothing, and I don't know how to do it (i.e. fake the system time of a process of which I have no control). – Martin R-L Feb 03 '12 at 13:54
  • 1
    Maybe it would help if you could show the usage of `SystemDateTime` in your unit tests. – Daniel Hilgarth Feb 03 '12 at 14:00
  • @MartinR-L: create or update an instance of your `SystemDateTime` to pretend that desired amount of time has elapsed, then check whatever you want in the `Then` clause. Again, without the code I don't see any reason to communicate fake time with the server process. – Igor Korkhov Feb 03 '12 at 14:02
  • @MartinR-L I removed the code block formatting because it's not code. – Samuel Slade Feb 03 '12 at 14:09
  • @SamuelSlade: it *is* code, in a language called Gherkin: https://github.com/cucumber/cucumber/wiki/Gherkin – Igor Korkhov Feb 03 '12 at 14:17
  • @MartinR-L, Igor: Apologies, I stand corrected. – Samuel Slade Feb 03 '12 at 14:19

1 Answers1

0

I solved the problem by having the bootstrapping of the web app check whether to use a fake system clock or not.

I added a flag to the web.config. If true, the fake date + time is read from an environment variable.

The example/scenario simply sets the flag and environment variable accordingly as a part of its Given-steps.

Martin R-L
  • 4,039
  • 3
  • 28
  • 28